473,769 Members | 6,799 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

argument contravariance

Hello!!

Can somebody explain what does argument contravariance mean.
I know what covariance mean because this is involved in some way when we
have argument contravariance .

Use some easy code exampe to describe this.
//Tony
Oct 13 '05 #1
2 3435
* Tony Johansson:

Can somebody explain what does argument contravariance mean.
I know what covariance mean because this is involved in some way when we
have argument contravariance .

Use some easy code exampe to describe this.


That last sounds like HOMEWORK -- however...

Co-variant means that an argument type is more specialized in a more
specialized (a derived) class, that's what "co" -- with -- stands for.

I mention that, which you claim to know, because contra-variant is just the
opposite, and that shouldn't be too hard to guess... Or Google.

Co-variant is compatible with the Liskov Substitution Principle (LSP) for an
out-argument, and contra-variant is compatible with LSP for an in-argument.

C++ does not support designation of argument data flow direction except for
function return values, so C++ does not support co/contra-variant arguments
except for function return values, which are allowed to be [insert the right
term here, Tony, is it in or out?]. C# lets you specify that an argument is
an out-argument, but currently does not support [the right term] for arguments
designated as out. Ada allows you to designate arguments as in or out, but I
don't know what Ada supports regarding co- and contra-variance.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Oct 13 '05 #2
Alf P. Steinbach wrote:
* Tony Johansson:

Can somebody explain what does argument contravariance mean.
I know what covariance mean because this is involved in some way when we
have argument contravariance .

Use some easy code exampe to describe this.
That last sounds like HOMEWORK -- however...


I think it's also quite likely that the word "contravariance " came up
in some casual conversation, and the original poster was simply too
embarrassed to ask what such a commonly-used word means. And the
request for code samples I'm sure has an equally innocent motivation. I
just haven't thought of one yet.
Co-variant means that an argument type is more specialized in a more
specialized (a derived) class, that's what "co" -- with -- stands for.

I mention that, which you claim to know, because contra-variant is just the
opposite, and that shouldn't be too hard to guess... Or Google.

Co-variant is compatible with the Liskov Substitution Principle (LSP) for an
out-argument, and contra-variant is compatible with LSP for an in-argument.

C++ does not support designation of argument data flow direction except for
function return values, so C++ does not support co/contra-variant arguments
except for function return values, which are allowed to be [insert the right
term here, Tony, is it in or out?]. C# lets you specify that an argument is
an out-argument, but currently does not support [the right term] for arguments
designated as out. Ada allows you to designate arguments as in or out, but I
don't know what Ada supports regarding co- and contra-variance.


One example of contravariance in C++ would be type of object needed to
resolve a member pointer. In order to resolve a member pointer it is
necessary either to have an instance of the member pointer's class, or
of a derived class. Therefore we can say the type required to resolve a
member pointer is contravariant to the member pointer's class type.

Greg

Oct 13 '05 #3

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

Similar topics

1
373
by: Tony Johansson | last post by:
Hello!! In inheritance we have the same signature in the subklass as in the baseklass because the language require that(except covariat return typ) Now to my question assume that the language support argument contravarianc. What would the advantage be compare to having the same signature in the subklass as in the baseklass as it is required today.
5
1697
by: Booted Cat | last post by:
I've seen lots of discussions on the proposed inclusion of "function call with named arguments" to C/C++ on these newsgroups. My proposal is slightly different in that: * No ANSI approval is needed * No conflicts with existing language features such as function overloading * No need to modify the language spec or the compiler * No need to modify your source code
1
1053
by: Ben Voigt | last post by:
I've extended the article "Covariance and Contravariance in Delegates" from the C# Programmers' Guide, and it seems contravariance of delegates is implemented wrong. Lambda calculus states that Handler2Method is a subtype of HandlerMethod... why can't I convert? However the last line does work, but I'm not wanting to create new delegate objects. I'm actually implementing contravariant events, and I'm scared about my remove...
4
2385
by: Patient Guy | last post by:
Does anyone have any coding rules they follow when doing argument checking? When arguments fail during check, do you return from the call with an ambiguous return value, or do you throw exceptions?
1
3006
by: =?Utf-8?B?aGVyYmVydA==?= | last post by:
Jon Skeet wrote in the .NET general newsgroup 11/17/2005: "The difference between Invoke and DynamicInvoke is that the parameters to Invoke depend on the delegate itself - the method has the same signature as the delegate. DynamicInvoke has a "fixed" signature, and it dynamically calls Invoke with the appropriate parameters." So far I have seen DynamicInvoke only used in conjunction with generics event arguments. Is there any other...
8
2302
by: A. Anderson | last post by:
Howdy everyone, I'm experiencing a problem with a program that I'm developing. Take a look at this stack report from GDB - #0 0xb7d782a3 in strlen () from /lib/tls/i686/cmov/libc.so.6 #1 0xb7d4c2f7 in vfprintf () from /lib/tls/i686/cmov/libc.so.6 #2 0xb7d6441b in vsprintf () from /lib/tls/i686/cmov/libc.so.6 #3 0x08049ba0 in character_data::printf (this=0x800, argument=0x0) at character.c:198
4
3380
by: robert | last post by:
On a server the binary (red hat) installed python2.4 and also a fresh compiled python2.5 spits "sem_post: Invalid argument". What is this and how can this solved? Robert ============== server # python2.4 sem_post: Invalid argument
5
6641
by: puzzlecracker | last post by:
C++ standard says the following: I am reading through c++ standard and have a difficulty understanding the difference between these two terms. Thanks, puzzlecracker
3
2729
by: =?Utf-8?B?RnJhbmsgVXJheQ==?= | last post by:
Hi all I have some problems with Crystal Reports (Version 10.2, Runtime 2.0). In Section3 I have added a OLE Object (Bitmap). Now when I open the report in my code I would like to set this OLE Object (load a picture from a given path). Something like this I would expect: _reports.crImage local_Report = new _reports.crImage();
0
9590
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10051
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10000
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9866
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6675
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5310
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3571
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.