3 Replies - 10999 Views - Last Post: 28 September 2010 - 05:29 AM Rate Topic: -----

#1 dr_worm  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 144
  • Joined: 11-September 06

No instance of overloaded function

Posted 26 September 2010 - 08:20 PM

So I'm getting this crazy error at the commented line in the jump function, VS2010 says: "no instance of overloaded function [boils down to push] matches the argument list". Code as follows:
#include <queue>
#include <vector>

using namespace std;

class Move
{
public:
	int from, to;
};

class State
{
public:
	vector<int> state;
	queue<Move> moves;
};

void jump(State new_state)
{
	State cur_state = new_state;

	if(cur_state.state[4] && cur_state.state[5] && !(cur_state.state[6]))
	{
		Move new_move = {4, 6};
		cur_state.moves.push(new_move); //ERROR HERE: occurs at the . before push
	}
}

int main()
{
        State state;
        vector<int> init_state;
        for(int i = 0; i < 15; i++)
                init_state.push_back(1);
        state.state = init_state;
        jump(state);
        return 0;
}


That's pretty much the most basic test case I can come up with, and it compiles fine on codepad.org, but for some reason VS is giving me hell.

Has anyone dealt with something like this before? I'll make the files available upon request.

Thanks in advance.

Is This A Good Question/Topic? 0
  • +

Replies To: No instance of overloaded function

#2 eker676  Icon User is offline

  • Software Engineer
  • member icon

Reputation: 378
  • View blog
  • Posts: 1,833
  • Joined: 18-April 09

Re: No instance of overloaded function

Posted 26 September 2010 - 08:35 PM

I just compiled and ran in VS2010 without even a warning.

This post has been edited by eker676: 26 September 2010 - 08:36 PM

Was This Post Helpful? 0
  • +
  • -

#3 n8wxs  Icon User is offline

  • --... ...-- -.. . -. ---.. .-- -..- ...
  • member icon

Reputation: 972
  • View blog
  • Posts: 3,878
  • Joined: 07-January 08

Re: No instance of overloaded function

Posted 26 September 2010 - 08:46 PM

I don't get any errors.

VS2K8

I modified main() a bit to generate a 4-1, 5-1, 6-0:

...
for(int i = 0; i < 15; i++) {
    if (i == 6)
        init_state.push_back(0);
    else
        init_state.push_back(1);
}
...



I set a breakpoint and this is what I see:

new_state {state=[15](1,1,1,1,1,1,0,1,1,1,1,1,1,1,1) moves=[0]() }    State
cur_state {state=[15](1,1,1,1,1,1,0,1,1,1,1,1,1,1,1) moves=[1]({from=4 to=6 }) }    State
state    [15](1,1,1,1,1,1,0,1,1,1,1,1,1,1,1)    std::vector<int,std::allocator<int> >
moves    [1]({from=4 to=6 })    std::queue<Move,std::deque<Move,std::allocator<Move> > >


Was This Post Helpful? 0
  • +
  • -

#4 dr_worm  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 144
  • Joined: 11-September 06

Re: No instance of overloaded function

Posted 28 September 2010 - 05:29 AM

I'm about to shoot myself.

Added the following line to the top of the move.h file:

 #pragma once 


And my problem was solved INSTANTLY.

This post has been edited by dr_worm: 28 September 2010 - 05:30 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1