473,395 Members | 1,629 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

dereived class

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
2 1193
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
9,208 Expert Mod 8TB
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

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

Similar topics

1
by: Murat Tasan | last post by:
hi, i am having a small problem with constructing an inner class. i am using an inner class (and not a static nested class) because the methods of the inner class need access to the enclosing...
2
by: Fernando Rodriguez | last post by:
Hi, I need to traverse the methods defined in a class and its superclasses. This is the code I'm using: # An instance of class B should be able to check all the methods defined in B #and A,...
1
by: Oplec | last post by:
Hi, I'm learning C++ as a hobby using The C++ Programming Language : Special Edition by Bjarne Stroustrup. I'm working on chpater 13 exercises that deal with templates. Exercise 13.9 asks for me...
13
by: Bryan Parkoff | last post by:
I have created three classes according to my own design. First class is called CMain. It is the Top Class. Second class and third class are called CMemory and CMPU. They are the sub-classes....
9
by: Banaticus Bart | last post by:
I wrote an abstract base class from which I've derived a few other classes. I'd like to create a base class array where each element is an instance of a derived object. I can create a base class...
5
by: Andy | last post by:
Hi all, I have a site with the following architecture: Common.Web.dll - Contains a CommonPageBase class which inherits System.Web.UI.Page myadd.dll - Contains PageBase which inherits...
1
by: Roger Miller | last post by:
I'll try to keep my explanation as simple as I can but leave in the relevant details. We're developing in c#. Our main application can dynamically load assemblies ( plugins) that support a...
3
by: Hamilton Woods | last post by:
Diehards, I developed a template matrix class back around 1992 using Borland C++ 4.5 (ancestor of C++ Builder) and haven't touched it until a few days ago. I pulled it from the freezer and...
0
by: emin.shopper | last post by:
I had a need recently to check if my subclasses properly implemented the desired interface and wished that I could use something like an abstract base class in python. After reading up on metaclass...
1
by: jico12 | last post by:
hello, I am trying to write a program that uses two templated classes, one call Rek, which represents a record; and another called Table, which consists of an array of pointers to instances of Rek...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.