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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Why won't this work? 1

Status
Not open for further replies.

maluk

Programmer
Oct 12, 2002
79
SG
Why won't this work?

Code:
class Base
{
public:
   Base()
   {
   }

   Base(const char* msg)
   {
   }
} ;

class Sub : pulic Base
{
   Sub()
   {
   }

   Sub(const char* msg)
   {
      Base::Base(msg) ;
   }
} ;

Why isn't the above code the same as this one (that works):

Code:
class Base
{
public:
   Base()
   {
   }

   Base(const char* msg)
   {
   }
} ;

class Sub : pulic Base
{
   Sub()
   {
   }

   Sub(const char* msg) : Base(msg)
   {
   }
} ;

Rome did not create a great empire by having meetings, they did it by
killing all those who opposed them.

- janvier -
 
Constructor is not an ordinal function. You can't invoke ctor as other functions: it's C++ syntax rule. See Stroustrup's book about C++ design history...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top