Mail Archives: djgpp/1998/07/17/11:46:44
Message-ID: | <35AF6D43.16105684@ipass.net>
|
From: | Terry <iceman AT ipass DOT net>
|
MIME-Version: | 1.0
|
Newsgroups: | comp.os.msdos.djgpp
|
Subject: | Re: the call of the constructor
|
References: | <01bdb146$46cfea20$1c1f1bc4 AT default>
|
Lines: | 54
|
Date: | Fri, 17 Jul 1998 15:32:43 GMT
|
NNTP-Posting-Host: | ts4-61-ppp.ipass.net
|
NNTP-Posting-Date: | Fri, 17 Jul 1998 11:32:43 EDT
|
Organization: | iPass.Net
|
To: | djgpp AT delorie DOT com
|
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp
|
Jorge Ivan Meza Martinez wrote:
>
> Hello,
>
> I have a class that has an object of another class like attribute, something
> like this:
>
> class miClase
> {
> public:
> miClase ();
>
> private:
> Objeto k;
> }
>
> the Objeto class:
>
> class Objeto
> {
> public:
> Objeto ( String );
> }
>
> the problem is that when I am at miClase constructor I want to initalize the
> k object, but the compiler already called de () ( empty ) constructor, that
> the class Objeto hasn't.
>
> if I try in the miClase constructor something like "k = Objeto ( String
> ("string") )" I get many errors from Ios and others, if I try "k ( String
> ("string") )" it says that I cannot ( cast ) (Objeto)(miClase&).
>
Here is an option for you. First define "k" as a pointer:
class miClase
{
public:
miClase ();
~miClase (); // Destructor has been added
private:
Objeto *k;
}
Then inside miClase constructor:
k = new Objeto;
Don't forget to delete it in destructor:
delete k;
Terry
- Raw text -