inheritance - What is the cause of the "Undefined symbols for architecture x86_64:" error in C++? -


i'd know reason these files (or possibly others in project) don't want link. far know it's okay leave out constructor , destructor if define them in .h file, correct? did .h in project , isn't complaining. what's going on?

the error message:

undefined symbols architecture x86_64:   "basicarena::basicarena()", referenced from:       _main in main.o ld: symbol(s) not found architecture x86_64 clang: error: linker command failed exit code 1 (use -v see invocation) 

areainterface.h (for purposes of assignment, not allowed edit file)

class arenainterface {     public:         arenainterface(){}         virtual ~arenainterface(){}         // lots of pure virtuals here } 

basicarena.h

#ifndef __rpg__basicarena__ #define __rpg__basicarena__  #include <stdio.h> #include "arenainterface.h" #include "cleric.h"  using namespace std;  class basicarena : public arenainterface { public:     basicarena() {}     ~basicarena() {}     virtual bool addfighter(string info);     virtual bool removefighter(string name);     virtual fighterinterface* getfighter(string name);     virtual int getsize();  private:     vector<fighterinterface*> fighters; };  #endif /* defined(__rpg__basicarena__) */ 

basicarena.cpp

#include "basicarena.h" #include <sstream>  using namespace std; // member function definitions here 

cleric.h:

#ifndef __rpg__cleric__ #define __rpg__cleric__  #include <stdio.h> #include <iostream> #include "fighterinterface.h"  using namespace std;  class cleric : public fighterinterface { public:     cleric(string nam, int hp, int str, int spd, int mag, int dmg) : name(nam), maxhp(hp), strength(str), speed(spd), magic(mag), damage(dmg){}     ~cleric() {}     // lots of functions , data } 

main.cpp:

#include <iostream> #include "basicarena.h"  using namespace std;  int main() {     basicarena testarena;     cout << "it works.\n";     return 0; } 

update: commenting out declarations/definitions of basicarena allow program run, leaves me question of whether acceptable/desired final program.

okay don't know how worked, somehow after commenting out basicarena constructor , destructor, running program (it compiled , ran @ point) then reinstating them compiles , runs far know same code had. @ loss. i'm glad works.

most code had small error (such missing semicolon) causing linker issue.


Comments