This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Undefined References
On Dec 1, 2007 9:49 AM, Michael Sullivan <michael@espersunited.com> wrote:
...
> Is this right?
...
> because when I make, I still get errors...
...
> battle.o: In function `battle::battle()':
> battle.cpp:(.text+0x9e3): undefined reference to
Right--undefined. I forgot I've been messing with your code and had
defined the Character() constructor.
I'm not sure about all the rules, but I think you have several
choices. Since you declared the default constructor, you must define
it. If you don't declare it, it will be provided automatically and
that may not be what you want. Choices:
+ don't declare it
+ declare it private, don't define it
//header:
private:
Character();
+ declare it public, define it as noop
//header:
public:
Character(){}
+ declare it public, define it with actions
//header:
public:
Character();
//cpp
Character::Character()
{
name[0] = 0;
maxHP = 0;
maxMP = 0;
currentHP = 0;
currentMP = 0;
}
The latter is what I did. Ideally you can clean up your constructors
by organizing member variables and using initializer syntax, etc.
Other improvements for modern code include using STL strings, etc. I
highly recommend Scott Meyers' books--much food for though.
-Tom