Re: C++ constructors.
Re: C++ constructors.
- Subject: Re: C++ constructors.
- From: Jesper Storm Bache <email@hidden>
- Date: Wed, 13 May 2009 07:28:11 -0700
Your copy constructor is atypical because the argument is not const
(or a non reference).
You could change it to be:
Cbyte1::Cbyte1 (const Cbyte1 &val)
Secondly, it looks like your class is a template. In that case you may
either want:
template <typename T>
class Cbyte1
{
Cbyte1 (const Cbyte1<T> &val)
...
or (if you need to be able to convert between different types of Cbyte
in the cctor)
template <typename T>
class Cbyte1
{
template <typename U>
Cbyte1 (const Cbyte1<U> &val)
...
By the way "working on Windows" means working with Visual Studio. In
that case you should inquire which version of VS he is using.
The newer versions of VS has better C++ compliance.
Jesper
On May 13, 2009, at 7:16 AM, Тимофей Даньшин wrote:
Hi there.
Here is a C++ constructor that is said to work on Windows (i.e., the
guy who wrote it says it works on Win), but doesn't work on Mac. Is
there a way to fix it, except by replacing it with a "copy" method?
Cbyte1::Cbyte1 (Cbyte1 &val) {
m_size = val.m_size;
if (m_size == 0) {
m_totalmax = 0;
b = "";
return;
}
}
The errors I get are:
/Users/dtv/Documents/XCodeBuilds/dakakugodno/dakakugodno/Mtran2/
cbyte_suggest.cpp: In function 'void Test()':
/Users/dtv/Documents/XCodeBuilds/dakakugodno/dakakugodno/Mtran2/
cbyte_suggest.cpp:25: error: no matching function for call to
'Cbyte1::Cbyte1(Cbyte1)'
/Users/dtv/Documents/XCodeBuilds/dakakugodno/dakakugodno/Mtran2/
cbyte_suggest.cpp:13: note: candidates are: Cbyte1::Cbyte1(Cbyte1&)
/Users/dtv/Documents/XCodeBuilds/dakakugodno/dakakugodno/Mtran2/
cbyte_suggest.cpp:12: note: Cbyte1::Cbyte1(Cbyte1*)
/Users/dtv/Documents/XCodeBuilds/dakakugodno/dakakugodno/Mtran2/
cbyte_suggest.cpp:11: note: Cbyte1::Cbyte1(char*)
/Users/dtv/Documents/XCodeBuilds/dakakugodno/dakakugodno/Mtran2/
cbyte_suggest.cpp:10: note: Cbyte1::Cbyte1(int)
/Users/dtv/Documents/XCodeBuilds/dakakugodno/dakakugodno/Mtran2/
cbyte_suggest.cpp:25: error: initializing temporary from result of
'Cbyte1::Cbyte1(char*)'
/Users/dtv/Documents/XCodeBuilds/dakakugodno/dakakugodno/Mtran2/
cbyte_suggest.cpp:25: error: no matching function for call to
'Cbyte1::Cbyte1(Cbyte1)'
/Users/dtv/Documents/XCodeBuilds/dakakugodno/dakakugodno/Mtran2/
cbyte_suggest.cpp:13: note: candidates are: Cbyte1::Cbyte1(Cbyte1&)
/Users/dtv/Documents/XCodeBuilds/dakakugodno/dakakugodno/Mtran2/
cbyte_suggest.cpp:12: note: Cbyte1::Cbyte1(Cbyte1*)
/Users/dtv/Documents/XCodeBuilds/dakakugodno/dakakugodno/Mtran2/
cbyte_suggest.cpp:11: note: Cbyte1::Cbyte1(char*)
/Users/dtv/Documents/XCodeBuilds/dakakugodno/dakakugodno/Mtran2/
cbyte_suggest.cpp:10: note: Cbyte1::Cbyte1(int)
/Users/dtv/Documents/XCodeBuilds/dakakugodno/dakakugodno/Mtran2/
cbyte_suggest.cpp:25: error: initializing temporary from result of
'Cbyte1::Cbyte1(char*)'
PS. I do my best to persuade that dude that the code badly needs
refactoring, but he is reluctant.
Thank you in advance.
Timofey Danshin.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden