Error: Declaration is incomparable with 'function name'
What I'm trying to do is pass an object (class) into a function constructor. The code essentially looks like this:
class Primary{
Primary(void);
~Primary(void);
};
//champion.h
//looks like
public:
Champion(void);
Champion::Champion(char name1[], int stringLength, int type1, double health1, int fluid1, double armor1, double specialA1, double开发者_运维百科 damage);
char* getName(void);
double getHealth(void);
int getFluid(void);
double getArmor(void);
double getSpecialA(void);
double getDamage(void);
int type;
void setHealth(double health);
void setFluid(int fluid);
void setArmor(double armor);
void setSpecialA(double specialA);
void setDamage(double physDamage);
void setPrimary(Primary prime1);
//champion is another class
void Champion::setPrimary(Primary prime1)
{
prime = prime1
}
Most of my code is here http://codepad.org/PMHZNtF9
I get an error that says
Error: Declaration is incomparable with 'void Champion::setPrimary( prime)" (declared in champion.h)"
I'm not sure what this means but I know it's possible to pass an object of a class into a function via parameter. What am I doing wrong? to be a little bit more clear I would like to know what the error means. and as far as I know everything declared as is. take a look and give me some ideas as to what might be the problem and hopefully I have not one small typo!
Dumb question, but are these all in one file? If not, does champion.cpp (or whatever it's called) have a reference to the Primary
class, via #include "primary.h"
?
EDIT:
Okay, what you've shown so far compiles if I do a quick reconstruction. One immediate thing I see is in the last chunk of code you have there:
void Champion::setPrimary(Primary prime1)
{
prime = prime1
}
Where is prime defined? The only field I see right now is type, which is an int.
There is nothing wrong in the source code that you have shown here which will give the error you mentioned. So probably, you missed out something while copy pasting the code here. The error suggests that there is mis-match in the declaration for function Champion::setPrimary
Probably yo should check if its declaration exactly matches the definition in your code or else If you can use codepad and post a sample of your code which actually gives a error, We can help you better.
There are a few points to note in the code above:
prime
being used inside theChampion::setPrimary
is not declared inside theclass Champion
. Probably since you copy pasted the code maybe that section got left out.class Primary
declares its constructor asPrivate
, From the code pasted here it not sure that is intentional(don't see you usingSingleton
) or just amistake.
精彩评论