Board index » cppbuilder » Derived Class constructor

Derived Class constructor

Hi,

I have a problem with OOP.

Okay, let me explain what I am trying to do.
I have created a Base Class called, ChildForm and TxtChild is derived
from ChildFrm as shown below:

ChildForm header file:

class TChildForm:public TForm
{
   public:
      AnsiString Filename;
      __fastcall ChildForm(TComponent* Owner, AnsiString s);

Quote
};

ChildForm implementation file:

__fastcall TChildForm::TChildForm(TComponent* Owner, AnsiString s)
        : TForm(Owner)
{
        Filename = s;

Quote
}

TxtChild header file:

class TTextChild:public TChildForm
{
   public:
     __fastcall TTextChild(TComponent* Owner);

Quote
};

When I compile the project, I got the following error:

[C++ Error] TxtChild.cpp(16): E2285 Could not find a match for
'TChildForm::TChildForm(TComponent *)'

Well, the error is quite obvious, because I have modified the default
constructor by adding the extra AnsiString argument. Simple, all I need
to do now is to add the same argument into TxtChild.cpp's default
constructor and hope everything will work just fine......but that was
not the case though :(

Anyone could shed some light on this?
Many thanks.

--

UK Time:

--
Quote: To Know The Road Ahead, Ask Those Who Had Returned.

Michael

 

Re:Derived Class constructor


Sorry, just to add one more thing here, when I add the extra argument in
TxtChild.cpp's constructor, I got this error message when I compile
instead:

[C++ Error] TxtChild.cpp(16): E2451 Undefined symbol 's'

Quote
Mike wrote:

> Hi,

> I have a problem with OOP.

> Okay, let me explain what I am trying to do.
> I have created a Base Class called, ChildForm and TxtChild is derived
> from ChildFrm as shown below:

> ChildForm header file:

> class TChildForm:public TForm
> {
>    public:
>       AnsiString Filename;
>       __fastcall ChildForm(TComponent* Owner, AnsiString s);
> };

> ChildForm implementation file:

> __fastcall TChildForm::TChildForm(TComponent* Owner, AnsiString s)
>         : TForm(Owner)
> {
>         Filename = s;
> }

> TxtChild header file:

> class TTextChild:public TChildForm
> {
>    public:
>      __fastcall TTextChild(TComponent* Owner);
> };

> When I compile the project, I got the following error:

> [C++ Error] TxtChild.cpp(16): E2285 Could not find a match for
> 'TChildForm::TChildForm(TComponent *)'

> Well, the error is quite obvious, because I have modified the default
> constructor by adding the extra AnsiString argument. Simple, all I need
> to do now is to add the same argument into TxtChild.cpp's default
> constructor and hope everything will work just fine......but that was
> not the case though :(

> Anyone could shed some light on this?
> Many thanks.

> --

> UK Time:

> --
> Quote: To Know The Road Ahead, Ask Those Who Had Returned.

> Michael

--

UK Time:

--
Quote: To Know The Road Ahead, Ask Those Who Had Returned.

Michael

Re:Derived Class constructor


Quote
Mike <m...@uk.xyratex.com> writes:
> class TChildForm:public TForm
> {
>    public:
>       AnsiString Filename;
>       __fastcall ChildForm(TComponent* Owner, AnsiString s);
> };

> class TTextChild:public TChildForm
> {
>    public:
>      __fastcall TTextChild(TComponent* Owner);
> };

> When I compile the project, I got the following error:

> [C++ Error] TxtChild.cpp(16): E2285 Could not find a match for
> 'TChildForm::TChildForm(TComponent *)'

You didn't post the implementation of the TTextChild constructor,
which is where I'd assume the error is.  It must call the base class
constructor in its initializer list, and it must pass in an Owner AND
an AnsiString.  My guess is you're doing something like this:

__fastcall TTextChild::TTextChild(TComponent* Owner)
  : TChildForm(Owner)
{
  // whatever

Quote
}

But TChildForm takes an AnsiString, and you're calling it without
passing in one.

That's just my guess though, since I can't see the code that wasn't
posted. :)

HTH.

--
Chris (TeamB);

Re:Derived Class constructor


Anyway, thanks for answering my question. I appreciate it very much. But
I have solved my problem.

Okay, I will post my source code for those who r interested to have a
look at how I did it.

From,

Michael

Quote: Knowledge is power, and there's no end to it.

Quote
"Chris Uzdavinis (TeamB)" wrote:

> Mike <m...@uk.xyratex.com> writes:

> > class TChildForm:public TForm
> > {
> >    public:
> >       AnsiString Filename;
> >       __fastcall ChildForm(TComponent* Owner, AnsiString s);
> > };

> > class TTextChild:public TChildForm
> > {
> >    public:
> >      __fastcall TTextChild(TComponent* Owner);
> > };

> > When I compile the project, I got the following error:

> > [C++ Error] TxtChild.cpp(16): E2285 Could not find a match for
> > 'TChildForm::TChildForm(TComponent *)'

> You didn't post the implementation of the TTextChild constructor,
> which is where I'd assume the error is.  It must call the base class
> constructor in its initializer list, and it must pass in an Owner AND
> an AnsiString.  My guess is you're doing something like this:

> __fastcall TTextChild::TTextChild(TComponent* Owner)
>   : TChildForm(Owner)
> {
>   // whatever
> }

> But TChildForm takes an AnsiString, and you're calling it without
> passing in one.

> That's just my guess though, since I can't see the code that wasn't
> posted. :)

> HTH.

> --
> Chris (TeamB);

--

UK Time:

Other Threads