C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Re: return types for virtual overriden functions
Goto page 1, 2, 3  Next
 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language, library and standards
View previous topic :: View next topic  
Author Message
Dan McLeran
Guest





PostPosted: Fri Aug 01, 2003 3:21 pm    Post subject: Re: return types for virtual overriden functions Reply with quote



[email]vvenkatagr (AT) yahoo (DOT) com[/email] (venkat) wrote in message news:<fe69c8ea.0307312225.567922ec (AT) posting (DOT) google.com>...
Quote:
Why is this not allowed as against using reference types for return?

class A{
public:
virtual A fun(){
}

};

class B :public A{
public:
B fun(){
}
};

See the standard 10.3.5:

5 The return type of an overriding function shall be either identical to
the return type of the overridden function or covariant with the
classes of the functions.

---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]


Back to top
James Kuyper
Guest





PostPosted: Sat Aug 02, 2003 6:01 pm    Post subject: Re: return types for virtual overriden functions Reply with quote



[email]dan.r.mcleran (AT) seagate (DOT) com[/email] (Dan McLeran) wrote in message news:<19b0e504.0308010608.62f44796 (AT) posting (DOT) google.com>...
Quote:
vvenkatagr (AT) yahoo (DOT) com (venkat) wrote in message news:<fe69c8ea.0307312225.567922ec (AT) posting (DOT) google.com>...
Why is this not allowed as against using reference types for return?

class A{
public:
virtual A fun(){
}

};

class B :public A{
public:
B fun(){
}
};

See the standard 10.3.5:

5 The return type of an overriding function shall be either identical to
the return type of the overridden function or covariant with the
classes of the functions.

The question was why the standard says this; the original poster was
clearly already aware of the fact that the code is illegal.

In particular, the key question is, why does the standard restrict
covariance to pointers and references; why can't it apply to actual
objects of class type? The other responder has already answered that
question, so I won't bother.

---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]


Back to top
Daniel Frey
Guest





PostPosted: Mon Aug 04, 2003 5:02 pm    Post subject: Re: return types for virtual overriden functions Reply with quote



Eugene Alterman wrote:
Quote:
kuyper (AT) wizard (DOT) net (James Kuyper) wrote in message news:<8b42afac.0308020918.7445f0a1 (AT) posting (DOT) google.com>...

The other responder has already answered that
question, so I won't bother.

I would not consider that answer particularly accurate though.
The type of the result is the return type of the function being called
which is known at compile tome. It is copy-initialized with the
return from the overrider at run-time.

What if A doesn't have a copy-ctor?

Quote:
A pointer or a reference to a base class can be downcasted to a
pointer/reference to the run-time type of the object it refers to. But
initializing an object with an object of the derived class does not
make sense since the latter would be sliced and irreversibly lost.

What about the context of the call? Was it called from an A or from an
B? If it's a B

B b;
b.fun();

it should return a B without slicing. If the calling context is A,
slicing occurs. Slicing is bad, yes, but you'd also create an overhead
as the function called from A's vtable needs to be a different function
as the one in B's vtable. Probably just a small stub but anyway.

There are problems other than the one I mentioned in my first answer,
but in my eyes these problems are just a consequence of the basic
assumption that the caller provides the memory for the return value (the
return slot) and what would happen if we try to make the OP's code legal.

Regards, Daniel

--
Daniel Frey

aixigo AG - financial training, research and technology
Schloß-Rahe-Straße 15, 52072 Aachen, Germany
fon: +49 (0)241 936737-42, fax: +49 (0)241 936737-99
eMail: [email]daniel.frey (AT) aixigo (DOT) de[/email], web: http://www.aixigo.de

---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]


Back to top
Sebastian Moleski
Guest





PostPosted: Tue Aug 05, 2003 1:00 am    Post subject: Re: return types for virtual overriden functions Reply with quote

Quote:
"Daniel Frey" <daniel.frey (AT) aixigo (DOT) de> wrote

Eugene Alterman wrote:
[email]kuyper (AT) wizard (DOT) net[/email] (James Kuyper) wrote in message
news:<8b42afac.0308020918.7445f0a1 (AT) posting (DOT) google.com>...

The other responder has already answered that
question, so I won't bother.

I would not consider that answer particularly accurate though.
The type of the result is the return type of the function being called
which is known at compile tome. It is copy-initialized with the
return from the overrider at run-time.

What if A doesn't have a copy-ctor?

That's impossible. Every object has a copy-constructor whether it is implictly
defined by the compiler or explicitly by the class developer. That copy
constructor might not be accessible though.

sm


---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]


Back to top
Eugene Alterman
Guest





PostPosted: Tue Aug 05, 2003 2:22 am    Post subject: Re: return types for virtual overriden functions Reply with quote

[email]daniel.frey (AT) aixigo (DOT) de[/email] (Daniel Frey) wrote in message news:<bgl8bj$sor$1 (AT) swifty (DOT) westend.com>...
Quote:
Eugene Alterman wrote:
[email]kuyper (AT) wizard (DOT) net[/email] (James Kuyper) wrote in message news:<8b42afac.030802
[email]0918.7445f0a1 (AT) posting (DOT) google.com[/email]>...

The other responder has already answered that
question, so I won't bother.

I would not consider that answer particularly accurate though.
The type of the result is the return type of the function being called
which is known at compile tome. It is copy-initialized with the
return from the overrider at run-time.

What if A doesn't have a copy-ctor?

Then it may not be used as a pass-by-value parameter or return type.

Quote:
A pointer or a reference to a base class can be downcasted to a
pointer/reference to the run-time type of the object it refers to. But
initializing an object with an object of the derived class does not
make sense since the latter would be sliced and irreversibly lost.

What about the context of the call? Was it called from an A or from an
B? If it's a B

B b;
b.fun();

it should return a B without slicing. If the calling context is A,
slicing occurs.

It does not matter whether it is called "from A" or "from B" (whatever
that means). In your example the virtual function mechanism does not
need to be employed at all since the most derived object type (and the
final overrider) is known at compile time. And if you call a virtual
function via a pointer or a reference there is no way to tell at
compile time what the final overrider would be.

Quote:
Slicing is bad, yes, but you'd also create an overhead
as the function called from A's vtable needs to be a different function
as the one in B's vtable.

What do you mean?

Quote:
Probably just a small stub but anyway.

No vtable thunk is necessary if there is no multiple inheritance.
OK, I don't know what you are talking about.

Quote:
There are problems other than the one I mentioned in my first answer,

What are they?

Quote:
but in my eyes these problems are just a consequence of the basic
assumption that the caller provides the memory for the return value (the
return slot)

You don't need to make any assumptions other than those explicitely
stated by the standard.

Quote:
and what would happen if we try to make the OP's code legal.

Nothing terrible will happen. It just would be totally useless.

Eugene

---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]


Back to top
Anders Dalvander
Guest





PostPosted: Tue Aug 05, 2003 2:37 pm    Post subject: Re: return types for virtual overriden functions Reply with quote

[email]sebmol (AT) yahoo (DOT) com[/email] ("Sebastian Moleski") wrote in message news:<vitvnbs20nqb28 (AT) corp (DOT) supernews.com>...
Quote:
What if A doesn't have a copy-ctor?

That's impossible. Every object has a copy-constructor whether it is implictly
defined by the compiler or explicitly by the class developer. That copy
constructor might not be accessible though.

What if the class has member variable of another class that has a non
accessible cctor, then the compiler can't define it implictly nor can
the developer define it explicitly. Is that cctor also non accessible
or non existent?

class foo
{
foo(const foo&); // private cctor
};

class bar
{
foo _foo;
// Does bar have a cctor or not?
};

---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]


Back to top
Daniel Frey
Guest





PostPosted: Tue Aug 05, 2003 2:37 pm    Post subject: Re: return types for virtual overriden functions Reply with quote

Eugene Alterman wrote:
Quote:
daniel.frey (AT) aixigo (DOT) de (Daniel Frey) wrote in message news:<bgl8bj$sor$1 (AT) swifty (DOT) westend.com>...

What if A doesn't have a copy-ctor?

Then it may not be used as a pass-by-value parameter or return type.

And what does it mean for the example?

Quote:
What about the context of the call? Was it called from an A or from an
B? If it's a B

B b;
b.fun();

it should return a B without slicing. If the calling context is A,
slicing occurs.

It does not matter whether it is called "from A" or "from B" (whatever
that means). In your example the virtual function mechanism does not

It means:

A a;
B b;
A a2 = a.fun();
B b2 = b.fun(); // No slicing here, no copy-ctor of A required
A a3 = b.fun(); // B returned, copy-ctor required, slicing

A* p = &b;
A a4 = p->fun(); // Huh??

The last call is the problem: p is of type A*, so the return type of
p->fun() is A. But B::fun() is called, which return a B. Without a stub,
how do you think this works? Compare it to 'b2' and 'a3'...

Quote:
need to be employed at all since the most derived object type (and the
final overrider) is known at compile time. And if you call a virtual
function via a pointer or a reference there is no way to tell at
compile time what the final overrider would be.

Should the language have separate rules for different cases? Should it
describle in detail how smart a compiler must be to find out the final
overriders?

Quote:
and what would happen if we try to make the OP's code legal.

Nothing terrible will happen. It just would be totally useless.

The standard doesn't allow this dangerous code (althought it might not
be useless depending on the context). It's just a trap that is avoided.
So what's your point? Are you arguing that the code should be legal
because "nothing terrible will happen"? Also, instead of complaining
about my inaccurate answer, why don't you provide a better and accurate
answer? :)

Regards, Daniel

--
Daniel Frey

aixigo AG - financial training, research and technology
Schloß-Rahe-Straße 15, 52072 Aachen, Germany
fon: +49 (0)241 936737-42, fax: +49 (0)241 936737-99
eMail: [email]daniel.frey (AT) aixigo (DOT) de[/email], web: http://www.aixigo.de

---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]


Back to top
Randy Maddox
Guest





PostPosted: Tue Aug 05, 2003 2:38 pm    Post subject: Re: return types for virtual overriden functions Reply with quote

[email]sebmol (AT) yahoo (DOT) com[/email] ("Sebastian Moleski") wrote in message news:<vitvnbs20nqb28 (AT) corp (DOT) supernews.com>...
Quote:
"Daniel Frey" <daniel.frey (AT) aixigo (DOT) de> wrote in message
news:bgl8bj$sor$1 (AT) swifty (DOT) westend.com...
Eugene Alterman wrote:
[email]kuyper (AT) wizard (DOT) net[/email] (James Kuyper) wrote in message
news:<8b42afac.0308020918.7445f0a1 (AT) posting (DOT) google.com>...

The other responder has already answered that
question, so I won't bother.

I would not consider that answer particularly accurate though.
The type of the result is the return type of the function being called
which is known at compile tome. It is copy-initialized with the
return from the overrider at run-time.

What if A doesn't have a copy-ctor?

That's impossible. Every object has a copy-constructor whether it is implictly
defined by the compiler or explicitly by the class developer. That copy
constructor might not be accessible though.

sm


What about a copy-ctor that the developer explicitly declares and does
not define? Say,

class A
{
A(const A &); // declaration only, no definition anywhere
};

This class does not have a copy-ctor.

Randy.

---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]


Back to top
Sebastian Moleski
Guest





PostPosted: Tue Aug 05, 2003 11:38 pm    Post subject: Re: return types for virtual overriden functions Reply with quote

"Randy Maddox" <rmaddox (AT) isicns (DOT) com> wrote

Quote:
sebmol (AT) yahoo (DOT) com ("Sebastian Moleski") wrote in message
news:<vitvnbs20nqb28 (AT) corp (DOT) supernews.com>...
That's impossible. Every object has a copy-constructor whether it is
implictly
defined by the compiler or explicitly by the class developer. That copy
constructor might not be accessible though.

What about a copy-ctor that the developer explicitly declares and does
not define? Say,

class A
{
A(const A &); // declaration only, no definition anywhere
};

This class does not have a copy-ctor.

That's a question of what "has" means <g>

To be exact, every object has a declared (although not necessarily accessible or
defined) copy constructor.

sm


---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]


Back to top
Dan McLeran
Guest





PostPosted: Wed Aug 06, 2003 1:52 am    Post subject: Re: return types for virtual overriden functions Reply with quote

Quote:
What about a copy-ctor that the developer explicitly declares and does
not define? Say,

class A
{
A(const A &); // declaration only, no definition anywhere
};

This class does not have a copy-ctor.

Randy.

I don't believe that this is valid code. I believe that if you provide
a copy ctr method declaration, you must provide implementation as
well. I put together a small file and got a linker error, with gcc &
MSVCSP5 anyways:

#include <iostream>
#include <stdlib.h>

using namespace std;

class A
{
public:
A()
{
cout<<"Ctr"< }
A(A const& copy);
};

int main(int argc, char *argv[])
{
A a;
A b(a); //comment this line out and you're ok
//the compiler generates a default copy ctr

system("PAUSE");
return 0;
}

gcc gave a linker error:

main.o(.text+0x3f):main.cpp: undefined reference to `A::A(A const&)'

MSVCSP5 gave this linker error:

main.obj : error LNK2001: unresolved external symbol "public:
__thiscall A::A(class A const &)" (??0A@@QAE@ABV0@@Z)
Debug/NoCopyCtr.exe : fatal error LNK1120: 1 unresolved externals

---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]


Back to top
Sebastian Moleski
Guest





PostPosted: Wed Aug 06, 2003 2:19 am    Post subject: Re: return types for virtual overriden functions Reply with quote

"Dan McLeran" <dan.r.mcleran (AT) seagate (DOT) com> wrote

Quote:
What about a copy-ctor that the developer explicitly declares and does
not define? Say,

class A
{
A(const A &); // declaration only, no definition anywhere
};

This class does not have a copy-ctor.

Randy.

I don't believe that this is valid code. I believe that if you provide
a copy ctr method declaration, you must provide implementation as
well.

Actually, that's not quite true. There's actually an idiom out there that takes
advantage of the fact that functions that aren't actually used don't have to be
defined either: if you want to specifically prevent copying and assignment
(which is sometimes necessary), you can declare the copy constructor and copy
assignment operator private and don't define it either.

Quote:
class A {
public:
A() {
std::cout << "Ctr" << std::endl;
}

A(A const& copy);
};

int main(int argc, char *argv[]) {
A a;
A b(a); //comment this line out and you're ok
//the compiler generates a default copy ctr

The difference here is that you are using the copy constructor. If you're not
using it, the compiler won't require it and the linker won't go looking for it
either. The comment "the compiler generates a default copy ctr" is incorrect. In
your example, no copy constructor is generated by the compiler.

sm


---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]


Back to top
Daniel Frey
Guest





PostPosted: Wed Aug 06, 2003 3:03 pm    Post subject: Re: return types for virtual overriden functions Reply with quote

Eugene Alterman wrote:
Quote:

Well, let us generalize the concept of covariance and call it weak
covariance:
If a function D::f overrides a function B::f, the return types of the
functions are weakly covariant if a return value from B::f can be
initialized with a return value from D::f.
It is easy to see that covariance implies weak covariance.
Replace "covariant" in 10.3.5 with "weakly covariant"
You can see then that if A doesn't have a copy-ctor than return types
of B::fun and A::fun are not weakly covariant and B is ill-formed.

Eugene,

please allow me to recap the thread so far, correct me if I'm wrong:

The OP asked why his example is "not allowed". This clearly addresses
the C++ programming language as it currently is as it was posted to
comp.std.c++.

I answered that (AFAIK) the root of the trouble is, that the function
should be able to store its result in a memory area provided by the
caller, which won't work for the OPs example. The language needn't
prescribe it, but I guess the language's authors don't want to render it
impossible as it is a very common and fast technique. Maybe you just
misread this as that I was saying that it's technically impossible, but
that wasn't my intend.

You said:

<quote>The type of the result is the return type of the function being
called which is known at compile tome. It is copy-initialized with the
return from the overrider at run-time.</quote>

IMHO, both sentences are wrong. I showed an example (p->fun()) where the
compiler doesn't know the return type at compile time and the second
sentence is not true for the current C++ language. This (especially the
last sentence) suggests to me that you think that the OPs example is
legal. If you are talking about a hypothetical language extension,
please say so, otherwise I'll always assume you are talking about
ISO/IEC 14882-1998, which, btw, does not have 10.3.5 - it's 10.3/5 ;)

During the ongoing discussion, we came to the conclusion that *if* the
above example would be legal, slicing would occur or we need a different
implementation model where the result is not stored in a memory area
provided by the caller. Slicing is a bad thing as it results in
supprising behaviour for the user and it's also inefficient (yes, I am
serious about the run-time overhead!). As a bonus, you need an
accessible copy-ctor for A, which is not needed for the current code.

Using another implementation leads to even more run-time costs which I
would be deeply concerned about. All these are consequences of trying to
make the OPs example legal despite what I described in my first answer.
So, once again: It's not technically impossible, but it's a very bad idea.

I hope I expressed myself clearly now. :)

Regards, Daniel

--
Daniel Frey

aixigo AG - financial training, research and technology
Schloß-Rahe-Straße 15, 52072 Aachen, Germany
fon: +49 (0)241 936737-42, fax: +49 (0)241 936737-99
eMail: [email]daniel.frey (AT) aixigo (DOT) de[/email], web: http://www.aixigo.de

---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]


Back to top
Randy Maddox
Guest





PostPosted: Wed Aug 06, 2003 4:07 pm    Post subject: Re: return types for virtual overriden functions Reply with quote

[email]dan.r.mcleran (AT) seagate (DOT) com[/email] (Dan McLeran) wrote in message news:<19b0e504.0308051407.19d7e593 (AT) posting (DOT) google.com>...
Quote:
What about a copy-ctor that the developer explicitly declares and does
not define? Say,

class A
{
A(const A &); // declaration only, no definition anywhere
};

This class does not have a copy-ctor.

Randy.

I don't believe that this is valid code. I believe that if you provide
a copy ctr method declaration, you must provide implementation as
well. I put together a small file and got a linker error, with gcc &
MSVCSP5 anyways:

#include #include
using namespace std;

class A
{
public:
A()
{
cout<<"Ctr"< }
A(A const& copy);
};

int main(int argc, char *argv[])
{
A a;
A b(a); //comment this line out and you're ok
//the compiler generates a default copy ctr

system("PAUSE");
return 0;
}

gcc gave a linker error:

main.o(.text+0x3f):main.cpp: undefined reference to `A::A(A const&)'

MSVCSP5 gave this linker error:

main.obj : error LNK2001: unresolved external symbol "public:
__thiscall A::A(class A const &)" (??0A@@QAE@ABV0@@Z)
Debug/NoCopyCtr.exe : fatal error LNK1120: 1 unresolved externals

---

It is indeed valid code, and the linker error you see is exactly the
desired effect. The class A deliberately did not provide a copy ctor,
so you cannot copy objects of class A, which was rather the point.

This is a useful idiom for classes that correspond to things that
cannot be copied. Say a mutex or some other system resource, or a
singleton object, or whatever. When the situation is such that
copying makes no sense, this is the idiom used to prevent it.

Randy.

---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]


Back to top
Andy Sawyer
Guest





PostPosted: Thu Aug 07, 2003 2:50 am    Post subject: Re: return types for virtual overriden functions Reply with quote

In article <bgq9u0$gqh$1 (AT) swifty (DOT) westend.com>,
on Wed, 6 Aug 2003 15:03:31 +0000 (UTC),
[email]daniel.frey (AT) aixigo (DOT) de[/email] (Daniel Frey) wrote:


Quote:
If you are talking about a hypothetical language extension, please say
so, otherwise I'll always assume you are talking about ISO/IEC
14882-1998, which, btw, does not have 10.3.5 - it's 10.3/5 Wink

I can't speak for Eugene, but some of us are talking about the language
as defined by ISO/IEC 14882:2003(E)....

Regards,
Andy S
--
"Light thinks it travels faster than anything but it is wrong. No matter
how fast light travels it finds the darkness has always got there first,
and is waiting for it." -- Terry Pratchett, Reaper Man

---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]


Back to top
Dan McLeran
Guest





PostPosted: Fri Aug 08, 2003 3:22 am    Post subject: Re: return types for virtual overriden functions Reply with quote

Quote:
class A {
public:
A() {
std::cout << "Ctr" << std::endl;
}

A(A const& copy);
};

int main(int argc, char *argv[]) {
A a;
A b(a); //comment this line out and you're ok
//the compiler generates a default copy ctr

The difference here is that you are using the copy constructor. If you're not
using it, the compiler won't require it and the linker won't go looking for it
either. The comment "the compiler generates a default copy ctr" is incorrect. In
your example, no copy constructor is generated by the compiler.


Oops! You're quite right, I fat-fingered my example. It should have been:

#include #include <stdlib.h>

using namespace std;

class A
{
public:
A()
{
cout<<"Ctr"< }
A(A const& copy);//comment this line out and you're ok
//the compiler generates a default copy ctr

};

int main(int argc, char *argv[])
{
A a;
A b(a);
system("PAUSE");
return 0;
}

---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]


Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language, library and standards All times are GMT
Goto page 1, 2, 3  Next
Page 1 of 3

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.