473,405 Members | 2,154 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

result covariant

Hello!!

When you have result covariance is it then necessary that you have
inheritance.

I mean can you have result covariance without having inheritance.

//Tony
Oct 12 '05 #1
4 1258
Tony Johansson wrote:
Hello!!

When you have result covariance is it then necessary that you have
inheritance.

I mean can you have result covariance without having inheritance.

//Tony


Inheritance is necessary. Even void* won't work. Try this:

struct A
{
virtual A* Create() const { return new A; }
virtual int* GetVal() const { return new int(); }
};

struct B : public A
{
virtual B* Create() const { return new B; } // Ok
virtual char* GetVal() const { return new char(); } //Error!
};

Cheers! --M

Oct 12 '05 #2
Tony Johansson wrote:
When you have result covariance is it then necessary that you have
inheritance.

I mean can you have result covariance without having inheritance.


"Covariance" by definition requires inheritance. Is it necessary for
a bicycle to have wheels?
Oct 12 '05 #3
Victor Bazarov wrote:
Tony Johansson wrote:
When you have result covariance is it then necessary that you have
inheritance.

I mean can you have result covariance without having inheritance.


"Covariance" by definition requires inheritance. Is it necessary for
a bicycle to have wheels?


But, Victor, that's "has-a" inheritance! Surely, you meant something
like "Is it necessary for a bicycle to be a mountain bike?" ;-)

Cheers! --M

Oct 12 '05 #4
mlimber wrote:
Victor Bazarov wrote:
Tony Johansson wrote:
When you have result covariance is it then necessary that you have
inheritance.

I mean can you have result covariance without having inheritance.


"Covariance" by definition requires inheritance. Is it necessary for
a bicycle to have wheels?

But, Victor, that's "has-a" inheritance! Surely, you meant something
like "Is it necessary for a bicycle to be a mountain bike?" ;-)


I think you're confusing what my analogy is for. It is necessary by
definition for a bicycle to have wheels to be a bicycle. It is necessary
by definition for covariance to involve inheritance. I wasn't implying
that a bicycle was covariant with wheels. Yes, a mountain bike would
probably be covariant with a bike if it inherited from it publicly.

V
Oct 12 '05 #5

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

Similar topics

7
by: Alex Vinokur | last post by:
Hello, Here is some program with virtual constructors. Is there any difference between * clone1() vs. clone2() * create1() vs. create2() ? It seems that it should be.
4
by: Tydr Schnubbis | last post by:
I've read an interview with Brian Kernighan here: http://www-2.cs.cmu.edu/~mihaib/kernighan-interview/index.html. The interviewer asks him, among other things, about the weaknesses of C. This is...
14
by: Stefan Slapeta | last post by:
Hi, this code does not compile in C#: class base_class {} class derived_class : base_class {} class A { public virtual base_class f()
13
by: Stephen Walch | last post by:
Error C2392 is hitting me hard! I have a managed C++ library that implements a bunch of fixed interfaces. For example, one interface is: public abstract interface IDbCommand { public...
2
by: Mike | last post by:
I keep running into the scenario below over and over again. Currently I get around not having covariant return types by using an interface and explicit property definitions which works to some...
16
by: Bob Hairgrove | last post by:
Consider the classic clone() function: class A { public: virtual ~A() {} virtual A* clone() const = 0; }; class B : public A { public:
6
by: miked | last post by:
Why are there still no covariant return types? All searches reveal no workarounds accept for using an interface which is a real pain. I wind up missing this capability almost every time I...
8
by: Alex Vinokur | last post by:
Here is a code from http://www.parashift.com/c++-faq-lite/virtual-functions.html#faq-20.8 -------------------------------------- class Shape { public: virtual ~Shape() { } // A...
3
by: kikazaru | last post by:
Is it possible to return covariant types for virtual methods inherited from a base class using virtual inheritance? I've constructed an example below, which has the following structure: Shape...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.