By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
463,114 Members | 762 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 463,114 IT Pros & Developers. It's quick & easy.

C++ Linker Error

P: 1
I just created a program and used public inheritance. when compiling I am getting linker error of this kind.
[Linker error] undefined reference to `Person::Person(char *)'

[Linker error] undefined reference to `Person::~Person(void)'

[Linker error] undefined reference to `Student::~Student(void)'
May 28 '07 #1
Share this Question
Share on Google+
1 Reply

P: 1,806
if you declare protoypes in a header
And you want to access a method declared in the header, then you need to firstly include the header file where you want to use it(which it sounds like you have done), and secondly make sure that the implementation of MyClass is in the path that the compiler is looking in.....

This goes for constructors/destuructors as well.
That is, somewhere (for now in the directory where you are compiling) you need to define
Expand|Select|Wrap|Line Numbers
  1. Person::Person(char* name)
  2. {
  3.   /* Do somethign with name */
  4. }
  6. Person::~Person(void)
  7. {
  8.  /* Do Get rid of type things */
  9. }
  11. Student::~Student(void)
  12. {
  13.   /* Do get rid of type things */
  14. }
May 28 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.