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

dereived class

P: 38
Hi,

I want to derive a class from the main class as shown in the code below. But I am not sure how can I deal with the constructors of both classes.


Expand|Select|Wrap|Line Numbers
  1. // erasing from map
  2. #include <iostream>
  3. #include <string>
  4. #include <queue>
  5. #include <stdio.h>
  6. #include <sstream>
  7. using namespace std;
  8.  
  9.  
  10. class ma
  11. {
  12.   ma(string st);
  13. };
  14.  
  15. class sub
  16.  :public ma
  17. {
  18. public:
  19.  sub(string a);
  20. };
  21.  
  22. int main ()
  23. {
  24.  
  25. std::string st = "hello";
  26. queue<sub*> test;
  27.  
  28. test.push(new sub(st));
  29.  
  30.   return 0;
  31. }
  32.  
  33.  
If I compile the this code I got this error message:
/tmp/ccQvbxR8.o: In function `main':

test.cpp:(.text+0xf6): undefined reference to `sub::sub(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
collect2: ld returned 1 exit status

May someone please help!!

Regards
Sep 1 '10 #1
Share this Question
Share on Google+
2 Replies


P: 39
you should implement (declare) the constructors.
Now they are just definitions.

the sub could look like:

Expand|Select|Wrap|Line Numbers
  1. class sub :public ma 
  2. public: 
  3.  sub(string a) : ma(a) {} 
  4. }; 
Sep 1 '10 #2

weaknessforcats
Expert Mod 5K+
P: 9,197
you should implement (declare) the constructors.
Now they are just definitions.
When you implement a function, that is when you code it, that is a definition.

When you code a function prototype, that is a declaration.
Sep 2 '10 #3

Post your reply

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