1

I have the following part of code in testtournamentmember.cpp

TournamentMember player1("Ian", "Smith", "1998-12-03");

TournamentMember player2 = TournamentMember(player1);
player1.setFirstName("Andrew");

with class TournamentMember.h defined as:

private:
char firstName[31];
char lastName[31];
char dateBirth[11];
static std::string location;
//static int numberMembers;
//static int difficulty;

public:
TournamentMember();
TournamentMember(char[], char[], char[]);
TournamentMember(const TournamentMember&);
~TournamentMember();

inline void setFirstName(char*);

and with TournamentMember.cpp with:

inline void TournamentMember::setFirstName(char* _firstName){
     strcpy(firstName, _firstName);
}

(I have all the other functions defined, but I didn't attached them). When I want to run the code, I receive undefined reference to 'TournamentMember::setFirtstName(char*). I do not understand what is wrong with my code, because I define the fuction setFirstName as char* in the class and also in the program.

mpelia
  • 43
  • 3

1 Answers1

1

Your definition of setFirstName in TournamentMember.cpp is marked inline. That means the definition exists only in TournamentMember.cpp; that definition is not accessible from other source files, such as testtournamentmember.cpp.

By the way, you should be getting this error when you go to compile the code, not run it. You might be using a process that compiles and runs in one step, but you should still be aware of the distinction.

JaMiT
  • 14,422
  • 4
  • 15
  • 31