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

Exception & copy constructor

Why does this compile:

if (err != Socket::errSuccess) {
switch (err) {
case Socket::errTimeout:
ConnectionIOException cio(new
string(myTCPStream->getErrorString()), ConnectionIOException::TIMEOUT);
throw cio;

default:
ConnectionIOException cio(new
string(myTCPStream->getErrorString()), ConnectionIOException::GENERAL);
throw cio;

}
}

and this not:

if (err != Socket::errSuccess) {
switch (err) {
case Socket::errTimeout:
throw ConnectionIOException (new
string(myTCPStream->getErrorString()), ConnectionIOException::TIMEOUT);

default:
throw ConnectionIOException (new
string(myTCPStream->getErrorString()), ConnectionIOException::GENERAL);
}
}

with this error:

Connection.cpp:85: error: no matching function for call to
`ConnectionIOException::ConnectionIOException(Conn ectionIOException)'
.../exceptions/ConnectionIOException.h:19: note: candidates are:
ConnectionIOException::ConnectionIOException(Conne ctionIOException&)
Connection.cpp:85: error: in thrown expression
Connection.cpp:88: error: no matching function for call to
`ConnectionIOException::ConnectionIOException(Conn ectionIOException)'
.../exceptions/ConnectionIOException.h:19: note: candidates are:
ConnectionIOException::ConnectionIOException(Conne ctionIOException&)
Connection.cpp:88: error: in thrown expression

Thanks,

Adam

Jul 22 '05 #1
1 1726
Adam wrote:
Why does this compile:
ConnectionIOException cio(new
string(myTCPStream->getErrorString()), ConnectionIOException::TIMEOUT); throw cio;
This copies the exception from the [non-const] object 'cio'. Thus,
a copy constructor of the form

| ConnectionIOException(ConnectionIOException&);

is sufficient.
throw ConnectionIOException (new
string(myTCPStream->getErrorString()), ConnectionIOException::TIMEOUT);

This, on the other hand, try to copy the temporary and thus requires
a copy constructor of the form

| ConnectionIOException(ConnectionIOException const&);

because temporaries cannot be bound to a non-const reference. The error
message exposes that you don't have a copy constructor taking a const
object as parameter:
../exceptions/ConnectionIOException.h:19: note: candidates are:
ConnectionIOException::ConnectionIOException(Conne ctionIOException&)

--
<mailto:di***********@yahoo.com> <http://www.dietmar-kuehl.de/>
<http://www.contendix.com> - Software Development & Consulting

Jul 22 '05 #2

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

Similar topics

2
by: dinks | last post by:
Hi, I'm new to C++ and have been assigned a task which i dont completely understand. Any help would be greately appreciated. Here is the problem: The class "linkedListType" use the "assert"...
3
by: Pierre Rouleau | last post by:
The std::exception class defined in the Standard C++ <exception> header specifies that the constructors could throw any exception becuase they do not have a throw() specification. Why is that? ...
10
by: ambar.shome | last post by:
Dear All, Whats the difference between a copy constructor and assignment operator. We can assign the values of member variables of one object to another object of same type using both of them....
11
by: Lloyd Dupont | last post by:
(not I use 2.0, so new return a "normal" pointer and gcnew return a managed one, my question below regarding new concern plain standart C++ allocator) - if I use the default new operator, are all...
8
by: toton | last post by:
HI, One more small doubt from today's mail. I have certain function which returns a pointer (sometimes a const pointer from a const member function). And certain member function needs reference...
3
by: Nindi73 | last post by:
Hi, I am in need of a deep copy smart pointer (Boost doesn't provide one) which doesnt require the contained types to have a virtual copy constructor. I wrote a smart pointer class that I think...
10
by: Rahul | last post by:
Hi Everyone, I have the following exception class, class E1 { }; class E2 {
4
by: George2 | last post by:
Hello everyone, Here is Bjarne's exception safe sample, http://www.research.att.com/~bs/3rd_safe.pdf template <class Tclass Safe {
5
by: Vijay | last post by:
Hi All, I am not able to figure out what exactly happening in below code. what is control flow. Can anyone clear my confusion? Code: class A { public: A(){cout<<"In Constructor\n";}
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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...
0
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,...

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.