Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

constructor problem very simple i think

Posted on 1999-07-09
8
Medium Priority
?
186 Views
Last Modified: 2010-04-02
Ok this is my base class
H:
class CINITreeItem  
{
public:
      CINITreeItem(const std::string &Section);
      virtual ~CINITreeItem();
private:
      std::string m_Section;
}
CPP:
CINITreeItem::CINITreeItem(const std::string &Section)
:m_Section(Section)
{

}

and this the calls I've derived
H:
class CINITreeApplItem : public CINITreeItem  
{
public:
      CINITreeApplItem();
      virtual ~CINITreeApplItem();
}

Now my Question(s):
Do I have to use the "const std::string &Section" as parameter for the derived class and how? I always get the following error message: no appropriate default constructor available.
0
Comment
Question by:SirSmokeALot
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 
LVL 7

Expert Comment

by:KangaRoo
ID: 1199618
You have to supply the parameter for the baseclass. If the derived class needs a default c'tor, then you must somehow provide a parameter for the base's c'tor.
0
 
LVL 7

Expert Comment

by:KangaRoo
ID: 1199619
You don't *have* to add the parameter to the derived class' c'tor:

CINITreeApplItem::CINITreeApplItem() : CINITreeItem(std::string("Some Default")) { //other stuff }
0
 

Author Comment

by:SirSmokeALot
ID: 1199620
? doesn't work that's why i asked the question
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:SirSmokeALot
ID: 1199621
Adjusted points to 75
0
 
LVL 7

Expert Comment

by:KangaRoo
ID: 1199622
This works, there is something else

class A  
{
public:
      A(const int&);
      virtual ~A();
private:
      int m;
};

A::A(const int& s)
{
  m = s;
}


class B : public A  
{
public:
B();
virtual ~B();
} ;

B::B() : A(3)
{
}

0
 
LVL 7

Accepted Solution

by:
KangaRoo earned 210 total points
ID: 1199623
Tested and ok:

class CINITreeItem  
{
      public:
            CINITreeItem(const std::string &Section);
            virtual ~CINITreeItem();
      private:
            std::string m_Section;
};

CINITreeItem::CINITreeItem(const std::string &Section) : m_Section(Section)
{

}

class CINITreeApplItem : public CINITreeItem  
{
      public:
            CINITreeApplItem();
            virtual ~CINITreeApplItem();
};


CINITreeApplItem::CINITreeApplItem()
  : CINITreeItem(std::string("Some Default"))
{

}


0
 
LVL 7

Expert Comment

by:KangaRoo
ID: 1199624
I did have to edit, use a semi-colon after class declarations! :)
0
 

Author Comment

by:SirSmokeALot
ID: 1199625
Oh I forgot them in my above sample sorry :)
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

660 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question