1
votes

I'm stuck, why am i getting an error: declaration is incompatible...

'void A::function(int,int,std::vector<_Ty> *)' : overloaded member function not found in 'A' error C2061: syntax error : identifier 'vector' 1> with 1> [ 1> _Ty=Point 1> ]

//cpp file
void A::function(int a, int b, vector<B> *p)
{    

}

//header file

class B
{
public:
     int q;
};
class A
{     
public:    
     void function(int a, int b, vector<B> *p);    
};
3
Call is now same as prototype yet still there is an errorel_pup_le
Can you post the A::function decleration in cpp file? And why is class B there?ali_bahoo
Edit: the function is protectedel_pup_le
Add #include <vector>.ali_bahoo
as sad_man said, add #include <vector> then using namespace std; to the header file. also perhaps you have written void A::function(int,int,std::vector<_Ty> *) instead of void A::function(int,int,std::vector<B> *) in a place.Tamer Shlash

3 Answers

4
votes

Problems!!!!

void function(int a, int b, vector<B> *line); and void function(int a, int b, vector<B> & line); are two different signatures (function prototypes).

More importantly there is no such keyword Class in C++.

3
votes

It's because the header of the function should be exactly the same.

//cpp file 
void A::function(int a, int b, vector<B>* c) { }  

//header file  
Class B {
public:
    int q; 
}; 
class A {
public:
    void function(int a, int b, vector<B> *line);     
}; 

or :

//cpp file 
void A::function(int a, int b, vector<B>& c) { }  

//header file  
Class B {
public:
    int q;
};
class A {
public:
    void function(int a, int b, vector<B> &line);     
}; 

However, when calling the function in the first case, you should replace the * with & if passing an object, so the local pointer will get the address of the passed object. Or manually pass a pointer.

1
votes

Well, for starters, you're missing a semicolon at the end of B. Additionally, you're using Class instead of class.

For the signature itself, your declaration (in the header file) takes a pointer to a vector while your definition (in the .cpp file) takes a reference.

//cpp file
void A::function(int a, int b, vector<B>& c) // // Arguments are an int, an int, and a vector<B> reference.
{    

}

//header file

class B
{
public:
     int q;
};

class A
{     
public:    
     void function(int a, int b, vector<B>& line);
        // Same arguments.
};