inheritance of conversion operator

F

frantz

Maybe a stupid question:
------------------------
Is there ihneritance for conversion operator?
If yes or no, what is the reason(s)...

Thanks for your help.

Example:
--------
class A {
public:
operator double() const {return d_ ;}
private:
double d_ ;
} ;

// does b have the operator double()?
class B: public A {
} ;
 
V

Victor Bazarov

frantz said:
Maybe a stupid question:

Yes, there is... 12.3.2/5 explicitly states that.
If yes or no, what is the reason(s)...

Why do you need a reason for 'yes'? Anyway, a derived class object IS-A
base class object. If a base class object can be converted to type T,
then the derived class object can be converted too (since it IS-A base
class object). IOW, any _behaviour_ is inherited.

There are two kinds of member functions that are not inherited:
constructors and destructors. Everything else is inherited. One
exception exists that requires a bit more code than usual: copy assignment
operator. It is usually simply _hidden_ by the class' own assignment op,
but can be brought into the derived class scope with 'using'.
Thanks for your help.

Example:
--------
class A {
public:
operator double() const {return d_ ;}
private:
double d_ ;
} ;

// does b have the operator double()?
class B: public A {
} ;

It should. Do you get an error or something?

V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,479
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top