Article View: alt.comp.lang.learn.c-c++
Article #349Re: class definition
From: TiTi
Date: Tue, 30 Nov 1999 00:00
Date: Tue, 30 Nov 1999 00:00
66 lines
2987 bytes
2987 bytes
> Hello great programmers, I got a question here. Please take a look
You already know that much I see ...
> class derived : public base {
> public:
> derived() : base() {} file://What the hell does this line
of
> }
Every class has a constructor (either implicitly/explicitly defined), which
is declared with the same name as your class (derived). So, the part:
derived()
is the declaration of the constructor, what follows is the definition of the
constructor. A constructor is used to initialize the created object. Part of
this initialization includes initializing subobjects, such as base class
subobjects and member subobjects. The initialization of a base class
subobject is either implicit or explicit. Taking your example, an implicit
initialization of the base class subobject would be implemented as follows
(supposing the class 'base' has a default constructor (either
implicitly/explicitly defined)):
derived() {} // the constructor for the base class subobject is
implicitly called
An explicit initialization of a base class subobject is what you did:
derived() : base() {} // constructor for the base class subobject is
explicitly called
In any way, a base class subobject has to be constructed, either
implicitly/explicitly. If your 'base' class would not have a default
constructor (suppose the constructor for class 'base' is declared as
follows:
base (int i);
, and no other constructors for class 'base' exist), then the implicit
initialization of the base class subobject of a 'derived' object would fail.
Examples:
derived : base() {} // fails, there exists no default constructor for
class 'base'
derived {} // fails, no default constructor exists for class 'base'
derived : base (1) {} // succeeds, explicit call to constrcutor for
class 'base'
> Well, something out of the content but I saw this in my C++ book and I
> can't make clear of them:
> int *(*(*ifunct_ptr)(int))[5];
> float (*(*ffunct_ptr)(int,int))(float);
> typedef double (*(*(*dfunct_ptr)())[5])();
> (*(*funtion_ary_ptrs())[5])();
> int func() const;
Yuck, I hate those. Sorry, can't help ya there.
TiTi
Technical Details
Message-ID:
<8209fp$mqo$1@trex.antw.online.be>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<38436F07.55AD215F@netvigator.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f8d38,1c86b0ff88e63dee X-Google-Attributes: gidf8d38,public X-Google-Thread: 114592,1c86b0ff88e63dee X-Google-Attributes: gid114592,public X-Google-Thread: 109fba,1c86b0ff88e63dee X-Google-Attributes: gid109fba,public From: "TiTi" <Tha.Main.Man@Czernia.quadrantX09> Subject: Re: class definition Date: 1999/11/30 Message-ID: <8209fp$mqo$1@trex.antw.online.be> X-Deja-AN: 554796479 References: <38436F07.55AD215F@netvigator.com> X-Priority: 3 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2918.2701 Organization: Customer of Online Internet X-MSMail-Priority: Normal Newsgroups: alt.comp.lang.learn.c-c++,comp.lang.c++,borland.public.cpp.language