I have never had this problem before, and now i'm adding classes to my RPG, and all of the sethp,mp,etc says [Linker error] undefined reference to `User::sethp(int)' or something like that. What's wrong?
I have never had this problem before, and now i'm adding classes to my RPG, and all of the sethp,mp,etc says [Linker error] undefined reference to `User::sethp(int)' or something like that. What's wrong?
I'm a beginner C++ programmer, but I have studied HTML and Java. So if you need to help me I should catch on fast =)
You're calling User::sethp(int), and it isn't declared.
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.
You may have declared a method for your class but you lack the implementation for it, as an example:
The class has a method called bar declared but there is no implementation for it anywhere. You would need to add the implementation:Code:class myclass { public: void bar(void); }; int main() { myclass foo; foo.bar(); return 0; }
Code:void myclass::bar(void) { ... }
"Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
-Christopher Hitchens
yea just went back in some tuts and found that out. I learned inhertiance and some poly, and i didn't know something like that, dumb.
I'm a beginner C++ programmer, but I have studied HTML and Java. So if you need to help me I should catch on fast =)
oh I get it now... I thought u didn't have to do that
I thought u could just sethp();
doesn't work as an example?Code:class User public: User(); ~User(); int gethp() { return hp } void sethp(int hp); private: int hp }
I'm a beginner C++ programmer, but I have studied HTML and Java. So if you need to help me I should catch on fast =)
Well, aside from the missing semicolons and bracket, that would need the implementation for the sethp method for it to work. You could either include the implementation as you've done with the gethp method (as a part of the class declaration) or you would need to define it elsewhere.Code:class User { public: User(); ~User(); int gethp() { return hp; } void sethp(int hp); private: int hp; };
"Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
-Christopher Hitchens