473,795 Members | 3,428 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

VS2005 - question about copy-ctor

Hello all,

find below an example which IMO should refuse to compile. It compiles fine
with VS2005.

What happens in the call?
What is your opinion?

Kind regards,
Patrick

class noncopyable
{
protected:
noncopyable() {}
~noncopyable() {}
private:
// hide the copy-ctor and assignment
noncopyable( noncopyable const & );
const noncopyable& operator=( noncopyable const & );
};
class A : public noncopyable // inherit to avoid copying
{
noncopyable copy_protection ; // make member to avoid copying
};
int main()
{
//A a;
//A b = a; // this fails to compile

A c = A(); // this compiles fine

return 0;
}
Mar 24 '06 #1
18 1346
Patrick Kowalzick wrote:
Hello all,

find below an example which IMO should refuse to compile. It compiles fine
with VS2005.

What happens in the call?
What is your opinion?
I agree that it shouldn't compile, and for 2 separate reasons:

1: A's default constructor cannot access the default constructor for the
member copy_protection - remember that protected access only gives you
access to protected members of bases through pointers, references and
objects of the derived class, not the base class (this is to prevent one
derived class from breaking objects of other derived classes derived
from the same base). As a result, A doesn't have a well-formed default
constructor, so even "A a;" shouldn't compile. This is covered in 11.5/1
of the standard.

Delete the member copy_protection to get around this, and try a
different compiler to get the error in the first place.

2: In the call, "c" is copy initialized from a default constructed A.
The compiler is allowed to optimize out the copy, but according to the
standard it must check that the copy could be made (e.g. that there is
an accessible copy constructor). This is covered in 12.2/1 of the standard.

Again, use a different compiler to get the error.
class A : public noncopyable // inherit to avoid copying
{
noncopyable copy_protection ; // make member to avoid copying
};
Should be:

class A : noncopyable // no need for public inheritance
{
};


int main()
{
//A a;
//A b = a; // this fails to compile

A c = A(); // this compiles fine

return 0;
}


You may want to report the bugs to MS.

Tom
Mar 24 '06 #2
Hello Tom,

I agree that it shouldn't compile, and for 2 separate reasons:

1: A's default constructor cannot access the default constructor for the
member copy_protection - remember that protected access only gives you
access to protected members of bases through pointers, references and
objects of the derived class, not the base class (this is to prevent one
derived class from breaking objects of other derived classes derived from
the same base). As a result, A doesn't have a well-formed default
constructor, so even "A a;" shouldn't compile. This is covered in 11.5/1
of the standard.

Delete the member copy_protection to get around this, and try a different
compiler to get the error in the first place.
Normally, I do not use a member copy_protection . It was just to test VS2005
:).
2: In the call, "c" is copy initialized from a default constructed A. The
compiler is allowed to optimize out the copy, but according to the
standard it must check that the copy could be made (e.g. that there is an
accessible copy constructor). This is covered in 12.2/1 of the standard.

Again, use a different compiler to get the error.
VS2005 is the first, where I do not get the error. I was a little bit
surprised, as this is quite basic stuff. But perhaps MS will launch a 8.1
soon :). 8.0 is a little bit annoying sometimes.
class A : public noncopyable // inherit to avoid copying
{
noncopyable copy_protection ; // make member to avoid copying
};


Should be:

class A : noncopyable // no need for public inheritance
{
};


True.
You may want to report the bugs to MS.


Yes, I want. There is antoherone I want to report, but I do not know how. I
googled a little bit, but was not successful, yet.

Regards,
Patrick
Mar 24 '06 #3
You may want to report the bugs to MS.


Yes, I want. There is antoherone I want to report, but I do not know how.
I googled a little bit, but was not successful, yet.


You can do that here:
http://lab.msdn.microsoft.com/produc...k/default.aspx

Then, after you did that you can post the url here so that we can validate
it and vote for it.

--

Kind regards,
Bruno van Dooren
br************* *********@hotma il.com
Remove only "_nos_pam"
Mar 24 '06 #4
Hello all,
You may want to report the bugs to MS.


Yes, I want. There is antoherone I want to report, but I do not know how.
I googled a little bit, but was not successful, yet.


You can do that here:
http://lab.msdn.microsoft.com/produc...k/default.aspx

Then, after you did that you can post the url here so that we can validate
it and vote for it.


I posted it here:
http://lab.msdn.microsoft.com/Produc...ckid=FDBK47765

I wanted to refer to
http://lab.msdn.microsoft.com/produc...ckid=FDBK18668

but I did not manage it. I opened a new one, because the latter one refers
to the beta-version.

Regards,
Patrick
Mar 24 '06 #5
Patrick Kowalzick wrote:
Hello all,

You may want to report the bugs to MS.

Yes, I want. There is antoherone I want to report, but I do not know how.
I googled a little bit, but was not successful, yet.


You can do that here:
http://lab.msdn.microsoft.com/produc...k/default.aspx

Then, after you did that you can post the url here so that we can validate
it and vote for it.

I posted it here:
http://lab.msdn.microsoft.com/Produc...ckid=FDBK47765

I wanted to refer to
http://lab.msdn.microsoft.com/produc...ckid=FDBK18668

but I did not manage it. I opened a new one, because the latter one refers
to the beta-version.


Just to clarify, the following program should *not* compile - if it does
in VS2005 (which I don't have handy), it's another bug which should be
reported:

class Foo
{
protected:
Foo(){}
};

class Bar: public Foo
{
Foo f;
};

int main()
{
Bar b;
}

Tom
Mar 24 '06 #6
Tom Widmer [VC++ MVP] wrote:
Just to clarify, the following program should *not* compile - if it
does in VS2005 (which I don't have handy), it's another bug which should
be
reported:

class Foo
{
protected:
Foo(){}
};

class Bar: public Foo
{
Foo f;
};

int main()
{
Bar b;
}


It does compile with VC8. Looks like another bug is needed.

-cd
Mar 24 '06 #7
> Just to clarify, the following program should *not* compile - if it does
in VS2005 (which I don't have handy), it's another bug which should be
reported:

class Foo
{
protected:
Foo(){}
};

class Bar: public Foo
{
Foo f;
};

int main()
{
Bar b;
}


I posted it here:

http://lab.msdn.microsoft.com/Produc...ckId=FDBK47867

I messed up the class namig, but it should be understandable :).

Regards,
Patrick
Mar 27 '06 #8
Patrick Kowalzick wrote:
Just to clarify, the following program should *not* compile - if it does
in VS2005 (which I don't have handy), it's another bug which should be
reported:

class Foo
{
protected:
Foo(){}
};

class Bar: public Foo
{
Foo f;
};

int main()
{
Bar b;
}

I posted it here:

http://lab.msdn.microsoft.com/Produc...ckId=FDBK47867

I messed up the class namig, but it should be understandable :).


Great. It's about time I installed VC8 I think, then I could at least
validate the bug.

Tom
Mar 28 '06 #9
Hello all,
>You may want to report the bugs to MS.

Yes, I want. There is antoherone I want to report, but I do not know
how. I googled a little bit, but was not successful, yet.

You can do that here:
http://lab.msdn.microsoft.com/produc...k/default.aspx

Then, after you did that you can post the url here so that we can
validate it and vote for it.

I posted it here:
http://lab.msdn.microsoft.com/Produc...ckid=FDBK47765

I wanted to refer to
http://lab.msdn.microsoft.com/produc...ckid=FDBK18668

but I did not manage it. I opened a new one, because the latter one
refers to the beta-version.


MS marked the bug as resolved with the note that
A a = A();

is a direct initialization. As I wondered what the difference between this
and
A a;

shall be, I just posted in comp.lang.c++.m oderated.

Regards,
Patrick
Apr 3 '06 #10

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

Similar topics

7
1712
by: Mike | last post by:
Hi, I have read the Microsoft Product Feature Comparisons page many times over (http://msdn.microsoft.com/vstudio/products/compare/default.aspx), as well as Gregory's blog on the subject (http://spaces.msn.com/members/gregorybeamer/Blog/cns!1ptsyfBgfiUmsaQCul95SOyg!141.entry) however some things are still unclear to me. Specifically:
9
1702
by: Jeff Gaines | last post by:
I have just installed VS 2005 (MSDN version) and I am having problems coping files to the Projects folder while VS2005 is running. The projects folder is on a network share and I have used mscorfg.msc to set permissions as follows: Machine | Code Groups | All_Code | LocalIntranetZone | Copy of DataShare file://\\Jgsvr\DataShare\*.
0
920
by: joey.powell | last post by:
VS2005 Windows Forms App (Native), Tab Control that contains several tab pages. After changing background color off of transparent for a tab page, it always gets "stuck" and will no longer respond to user input for background color. As a workaround, I had to copy off all of the controls, remove the tab page, add another one, and then copy the controls back to the new tab page. I am still searching for an answer for my earlier post...
10
2540
by: musosdev | last post by:
Hi guys I'm trying to migrate to VS2005... I've managed to do that, but realised I'd opened my web projects as file projects, and I'm getting the error about network BIOS command limit. Anyway, I decided to have a go at loading them as web projects from our Win2k3 server. It gets so far and then says "The web server does not appear to have FrontPage server extensions installed".
2
1921
by: GW | last post by:
After the conversion and fixing some errs VS2005 threw, project ran OK. Opened xxx.vbproj file after the conversion to VS2005 from VS2003. Changed (usng wordpad) ../msbuild/2003 to 2005 thinking that should read 2005 Unable to open project after that. Chgd back to 2003. Unable to open. Err unable to read xxx.vbproj(218,16)
4
1510
by: WXS | last post by:
In a case you have Project/Assembly A references Project/Assembly B which References Project/Assembly C. Let's say Project A needs be and references it directly. Unknown to A, B needs project C's assembly but it uses C's assembly dynamically (Load Assembly). Even with copy Local set on all references Project A when built will get project B's output but not project C's. This is from what I hear due to an "enhancement" in VS2005, that...
10
2099
by: Frank | last post by:
I've done this a few times. In a solution I have a project, Say P1, and need another project that will contain much code that is similar to that of P1. I hope no one gets hung up on why I don't somehow share the code. So, I copy the folder P1 is in, change the new folder name, and is VS2005 to change all occurrences of P1's name tp P2's name.
3
1606
by: rmgalante | last post by:
I have a pretty large web site with about 400 files after I precompile it. When I use the VS2005 Publish tool and publish to an FTP site, which is running IIS, most of the attempts hang after about 10 minutes. Sometimes it works; sometimes it doesn't. Most times it doesn't. What is really aggravating is that I get no error message from VS2005 when the publish utility stops. It just stops. The only way I can tell that something is wrong...
2
1341
by: Jeff | last post by:
Hey In VS2005 I've copied some text to the clipboard, but when I paste it, I get something I previuosly added to the clipboard. I thought a reboot of my computer would help, but it didn''t.... after this problem occured, I've done a test where I copyed text from TextPad to vs2005 and that works. - but after this test, I again tryed to copy & paste within vs2005, but vs2005 pastes something I've previously
5
1201
by: Kardon Coupé | last post by:
Dear All, I'm bemused, I'm moving an application I've written from VB6 into VS2005, and I'm getting all the fundamentals over before I delve into the hard part, like getting the forms layout etc....and the simple things, like the 'About' option, opens another form.... Well here is the problem (which has me stumped).... My VB6 Application, I click 'About' and it opens a form, from that form,
0
9672
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...
1
10164
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
10001
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
9042
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6780
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
5437
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
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4113
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 we have to send another system
2
3723
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.