public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* RE: Question on derived class?
@ 2004-11-19 10:55 Pradip Singh
  0 siblings, 0 replies; 5+ messages in thread
From: Pradip Singh @ 2004-11-19 10:55 UTC (permalink / raw)
  To: Ishwar Rattan, gcc-help

Hi All,

   It is possible to access a->reset() by runtime polymorphism concept in c++. But in ur code the assignment A *a = b is wrong. It should be A *a = &b; But I donot know what u mean by pure virtual class. If it is a class contianing some pure virtual methods then it is called abstract class. And remember to define the pure virtual functions in A in b. Otherwise B will also become abstract class and u cannot create its object. So the very statement static B b; will start throwing compilation error.

But this is not the right forum to ask such question. Find some other C++ forum.

thanks and regards,
Pradip

-----Original Message-----
From: gcc-help-owner@gcc.gnu.org [mailto:gcc-help-owner@gcc.gnu.org]On
Behalf Of Ishwar Rattan
Sent: Friday, November 19, 2004 5:40 AM
To: gcc-help@gcc.gnu.org
Subject: Question on derived class?



Assume that A is pure virtual class with some public
methods.

B is derived from A

Class B : virtual A {
public:
     // all methods of A are defined here +
     A new method is also defined (here only)
     -- call it reset()
protected:
     // ...
};

Now B is initiated as

static B b;
A *a = b;

Is it possible to access b.reset() using a->reset()?

-ishwar


^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: Question on derived class?
       [not found] ` <363801FFD7B74240A329CEC3F7FE4CC4030964F6@ntxboimbx07.micro n.com>
@ 2004-11-19  1:02   ` Eljay Love-Jensen
  0 siblings, 0 replies; 5+ messages in thread
From: Eljay Love-Jensen @ 2004-11-19  1:02 UTC (permalink / raw)
  To: lrtaylor, ishwar, gcc-help

Hi Lyle,

 >How is that possible, since 'A' does not have a reset method in it?

It is possible.  By putting the virtual reset() method in the A interface 
class.

(Obviously, I didn't go into details as to the implementation.  Ishwar's 
question only asked if it was possible or not.)

 >Shouldn't only methods defined in 'A' be able to be called on 'a'?

Correct.  :-)

Sincerely,
--Eljay

^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: Question on derived class?
@ 2004-11-19  0:22 lrtaylor
       [not found] ` <363801FFD7B74240A329CEC3F7FE4CC4030964F6@ntxboimbx07.micro n.com>
  0 siblings, 1 reply; 5+ messages in thread
From: lrtaylor @ 2004-11-19  0:22 UTC (permalink / raw)
  To: eljay, ishwar, gcc-help

How is that possible, since 'A' does not have a reset method in it?  At
the time he tries to call a->reset(), the compiler won't know the method
can be called.  Shouldn't only methods defined in 'A' be able to be
called on 'a'?

Thanks,
Lyle


-----Original Message-----
From: gcc-help-owner@gcc.gnu.org [mailto:gcc-help-owner@gcc.gnu.org] On
Behalf Of Eljay Love-Jensen
Sent: Thursday, November 18, 2004 5:20 PM
To: Ishwar Rattan; gcc-help@gcc.gnu.org
Subject: Re: Question on derived class?

Hi Ishwar,

Your question is a general C++ question, and off-topic for this forum.

 >Is it possible to access b.reset() using a->reset()?

Yes.

HTH,
--Eljay

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Question on derived class?
  2004-11-19  0:04 ` Question on derived class? Ishwar Rattan
@ 2004-11-19  0:20   ` Eljay Love-Jensen
  0 siblings, 0 replies; 5+ messages in thread
From: Eljay Love-Jensen @ 2004-11-19  0:20 UTC (permalink / raw)
  To: Ishwar Rattan, gcc-help

Hi Ishwar,

Your question is a general C++ question, and off-topic for this forum.

 >Is it possible to access b.reset() using a->reset()?

Yes.

HTH,
--Eljay

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Question on derived class?
  2004-11-01 20:25 static memeber initialization in constructor?? lrtaylor
@ 2004-11-19  0:04 ` Ishwar Rattan
  2004-11-19  0:20   ` Eljay Love-Jensen
  0 siblings, 1 reply; 5+ messages in thread
From: Ishwar Rattan @ 2004-11-19  0:04 UTC (permalink / raw)
  To: gcc-help


Assume that A is pure virtual class with some public
methods.

B is derived from A

Class B : virtual A {
public:
     // all methods of A are defined here +
     A new method is also defined (here only)
     -- call it reset()
protected:
     // ...
};

Now B is initiated as

static B b;
A *a = b;

Is it possible to access b.reset() using a->reset()?

-ishwar

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2004-11-19 10:55 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-11-19 10:55 Question on derived class? Pradip Singh
  -- strict thread matches above, loose matches on Subject: below --
2004-11-19  0:22 lrtaylor
     [not found] ` <363801FFD7B74240A329CEC3F7FE4CC4030964F6@ntxboimbx07.micro n.com>
2004-11-19  1:02   ` Eljay Love-Jensen
2004-11-01 20:25 static memeber initialization in constructor?? lrtaylor
2004-11-19  0:04 ` Question on derived class? Ishwar Rattan
2004-11-19  0:20   ` Eljay Love-Jensen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).