Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Why does this not work? (class prob) 1

Status
Not open for further replies.

RwDwR

Programmer
Aug 1, 2002
16
NL
On the following code I get an error for the TEST constructor, saying:
"cannot construct base class 'ELEMENT'"

WHY!?????

my.h file (part):
-----------------------------------------------------------
class ELEMENT
{
public:
string element_name;
string element_data;
vector<ELEMENT*> elements;

void get_element();

//constructor
ELEMENT(string _element_name, int teller);
//destructor
~ELEMENT();
};

class TEST : public ELEMENT
{
public:
// Constructor
TEST();
};
-----------------------------------------------------------

my.c file:
-----------------------------------------------------------
ELEMENT::ELEMENT( string _element_name , int teller )
{
if ( teller < 10 )
{
teller++;
element_name = _element_name;
if ( teller == 2 )
{
elements.push_back( new TEST() );
}
elements.push_back( new ELEMENT( _element_name , teller ) );
}
}

ELEMENT::~ELEMENT()
{
for ( int i = 0 ; i < elements.size() ; i++ )
{
cout << elements->element_name << &quot;deleted&quot;;
delete elements;
}
}

void
ELEMENT::get_element()
{
for ( int i = 0 ; i < elements.size() ; i++ )
{
cout << elements->element_name;
elements->get_element();
}
}

TEST::TEST()
{
element_name = &quot;test&quot;;
}
-----------------------------------------------------------
 
Well RwD, to answer my own question =P

I've seem to not define a default constructor for the base class, the following definition for the base class solves all:

class ELEMENT
{
public:
string element_name;
string element_data;
vector<ELEMENT*> elements;

void get_element();

//constructors
ELEMENT();
ELEMENT(string _element_name, int teller);
//destructor
~ELEMENT();
};
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top