473,434 Members | 1,405 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,434 software developers and data experts.

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 3388
* 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
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...
5
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...
1
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...
4
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...
1
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...
8
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 ...
4
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 ============== ...
5
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
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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
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
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...
0
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...

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.