Re: Undefined References

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Dec 1, 2007 9:49 AM, Michael Sullivan <michael@xxxxxxxxxxxxxxxx> 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

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux