473,498 Members | 1,992 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

inheritance of conversion operator

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 {
} ;

Jul 22 '05 #1
2 2371
frantz wrote:
Maybe a stupid question:
------------------------
Is there ihneritance for conversion operator?
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
Jul 22 '05 #2
Ok, it seems to work fine.
Thanks for the explanations ;-)

Jul 22 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
2040
by: Jürgen Kaminski | last post by:
Hello all, I got some legacy code where a template implements a non-templated interface. These classes are really HUGE, but it boils down to the following structure: class BaseClass { public:...
1
1143
by: fmaerten | last post by:
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:
3
2819
by: Heiko Hund | last post by:
Hi, I do not understand the deeper reason for the following compiler error $ g++ test.cpp test.cpp: In function `int main()': test.cpp:41: error: `std::basic_string<char,...
7
5090
by: lovecreatesbeauty | last post by:
The following shortened table comes from a big company's C++ technical document accompanied with its C++ compiler. This company's C++ compiler was/is very popular in Windows platform programming....
6
2080
by: Alan Johnson | last post by:
For various reasons I'd like to be able to inherit from the built in types, which obviously you cannot do. To get around this, I made a template to emulate the built in types. So far I can't find...
12
1702
by: Taylor | last post by:
I'm trying to understand inheritance. I'd like to make my own type of IPAddress lets call it myIp. The following gives me CS0029 error: Cannot implicitly convert type 'System.Net.IPAddress' to...
5
3594
by: eiji | last post by:
Hi folks, I hope this is not "off topic"! :-) Consider the next code: /* Declarations of types that could become platform-dependent */ #define MyChar char #define MyInt int
0
2030
by: erik.erikson | last post by:
I am getting a compiler error that I can't well explain or even understand the origin of (though I boiled it down close...). Below is a bare-bones example. What I am doing is defining the...
42
2643
by: coder_lol | last post by:
Thanks everyone again for contributing to helping me clear C++ confusions. I did some serious reading on copy constructors and assignments and I think I've got a good handle on the memory stuff. ...
0
7002
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7203
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6885
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5462
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4588
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3093
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3081
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1417
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
290
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.