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

compiler error I don't understand

compiling this line:

SmartPtr<LongWrapper, RefCount> p1=SmartPtr<LongWrapper, RefCount>(new
LongWrapper(1));

with SmartPtr being:

template <class T, template <class> class OwnershipPolicy>
class SmartPtr : public OwnershipPolicy<T> {
public:
explicit SmartPtr(T* pointer);
SmartPtr(SmartPtr<T, OwnershipPolicy>& otherPointer);
SmartPtr<T, OwnershipPolicy> &operator=(SmartPtr<T, OwnershipPolicy> &);
SmartPtr<T, OwnershipPolicy> &operator=(T*);
~SmartPtr();
bool isNULL() { return pointer_==NULL; }
T& operator*() const;
T* operator->() const;
private:
void deleteObject();
void copyPtr(SmartPtr<T, OwnershipPolicy>& otherPointer);
void copyPtr(T* otherPointer);
SmartPtr();
T* pointer_;

};

i get the following error:

test.cpp:22: no matching function for call to `SmartPtr<LongWrapper,
RefCount>::SmartPtr(SmartPtr<LongWrapper, RefCount>)' smartptr.h:105:
candidates are: SmartPtr<T, OwnershipPolicy>::SmartPtr(SmartPtr<T,
OwnershipPolicy>&) [with T = LongWrapper, OwnershipPolicy = RefCount]

wich I don't understand.
Jul 19 '05 #1
7 1952

"Tobias Langner" <to************@t-online.de> wrote in message
news:bg*************@news.t-online.com...
compiling this line:

SmartPtr<LongWrapper, RefCount> p1=SmartPtr<LongWrapper, RefCount>(new
LongWrapper(1));

with SmartPtr being:

template <class T, template <class> class OwnershipPolicy>
class SmartPtr : public OwnershipPolicy<T> {
public:
explicit SmartPtr(T* pointer);
SmartPtr(SmartPtr<T, OwnershipPolicy>& otherPointer);
SmartPtr<T, OwnershipPolicy> &operator=(SmartPtr<T, OwnershipPolicy> &);
SmartPtr<T, OwnershipPolicy> &operator=(T*);
~SmartPtr();
bool isNULL() { return pointer_==NULL; }
T& operator*() const;
T* operator->() const;
private:
void deleteObject();
void copyPtr(SmartPtr<T, OwnershipPolicy>& otherPointer);
void copyPtr(T* otherPointer);
SmartPtr();
T* pointer_;

};

i get the following error:

test.cpp:22: no matching function for call to `SmartPtr<LongWrapper,
RefCount>::SmartPtr(SmartPtr<LongWrapper, RefCount>)' smartptr.h:105:
candidates are: SmartPtr<T, OwnershipPolicy>::SmartPtr(SmartPtr<T,
OwnershipPolicy>&) [with T = LongWrapper, OwnershipPolicy = RefCount]

wich I don't understand.


Compiles fine for me once I've added dummy definitions for LongWrapper and
RefCount. Post minimal, compilable code please.

john
Jul 19 '05 #2
"John Harrison" <jo*************@hotmail.com> wrote in message
news:bg************@ID-196037.news.uni-berlin.de...

"Tobias Langner" <to************@t-online.de> wrote in message
news:bg*************@news.t-online.com...
compiling this line:

SmartPtr<LongWrapper, RefCount> p1=SmartPtr<LongWrapper, RefCount>(new
LongWrapper(1));

with SmartPtr being:

template <class T, template <class> class OwnershipPolicy>
class SmartPtr : public OwnershipPolicy<T> {
public:
explicit SmartPtr(T* pointer);
SmartPtr(SmartPtr<T, OwnershipPolicy>& otherPointer);
SmartPtr<T, OwnershipPolicy> &operator=(SmartPtr<T, OwnershipPolicy> &); SmartPtr<T, OwnershipPolicy> &operator=(T*);
~SmartPtr();
bool isNULL() { return pointer_==NULL; }
T& operator*() const;
T* operator->() const;
private:
void deleteObject();
void copyPtr(SmartPtr<T, OwnershipPolicy>& otherPointer);
void copyPtr(T* otherPointer);
SmartPtr();
T* pointer_;

};

i get the following error:

test.cpp:22: no matching function for call to `SmartPtr<LongWrapper,
RefCount>::SmartPtr(SmartPtr<LongWrapper, RefCount>)' smartptr.h:105:
candidates are: SmartPtr<T, OwnershipPolicy>::SmartPtr(SmartPtr<T,
OwnershipPolicy>&) [with T = LongWrapper, OwnershipPolicy = RefCount]

wich I don't understand.


Compiles fine for me once I've added dummy definitions for LongWrapper and
RefCount. Post minimal, compilable code please.

Which compiler did you use? I did not compile it, since I was too laze
to add the dummy definitions, but as far as I can tell, it should not
compile. See my reply to the OP.

regards
--
jb

(replace y with x if you want to reply by e-mail)
Jul 19 '05 #3
"Tobias Langner" <to************@t-online.de> wrote in message
news:bg*************@news.t-online.com...
compiling this line:

SmartPtr<LongWrapper, RefCount> p1=SmartPtr<LongWrapper, RefCount>(new
LongWrapper(1));
The above call creates a temporary SmartPtr object which is used to copy
construct 'p1'.
with SmartPtr being:

template <class T, template <class> class OwnershipPolicy>
class SmartPtr : public OwnershipPolicy<T> {
public:
explicit SmartPtr(T* pointer);
SmartPtr(SmartPtr<T, OwnershipPolicy>& otherPointer);
SmartPtr<T, OwnershipPolicy> &operator=(SmartPtr<T, OwnershipPolicy> &);
The above copy c'tor and operator= both take a reference to a SmartPtr
object. But references cannot be bound to temporaries, which you are trying
to do above. This is the reason, why the copy c'tor and the operator= should
both take /const/ references, because temporaries /can/ be bound to those.
SmartPtr<T, OwnershipPolicy> &operator=(T*);
~SmartPtr();
bool isNULL() { return pointer_==NULL; }
T& operator*() const;
T* operator->() const;
private:
void deleteObject();
void copyPtr(SmartPtr<T, OwnershipPolicy>& otherPointer);
void copyPtr(T* otherPointer);
SmartPtr();
T* pointer_;

};

i get the following error:

test.cpp:22: no matching function for call to `SmartPtr<LongWrapper,
RefCount>::SmartPtr(SmartPtr<LongWrapper, RefCount>)' smartptr.h:105:
candidates are: SmartPtr<T, OwnershipPolicy>::SmartPtr(SmartPtr<T,
OwnershipPolicy>&) [with T = LongWrapper, OwnershipPolicy = RefCount]

wich I don't understand.


hth
--
jb

(replace y with x if you want to reply by e-mail)
Jul 19 '05 #4
Jakob Bieling wrote:
"Tobias Langner" <to************@t-online.de> wrote in message
news:bg*************@news.t-online.com...
compiling this line:

SmartPtr<LongWrapper, RefCount> p1=SmartPtr<LongWrapper, RefCount>(new
LongWrapper(1));


The above call creates a temporary SmartPtr object which is used to
copy
construct 'p1'.
with SmartPtr being:

template <class T, template <class> class OwnershipPolicy>
class SmartPtr : public OwnershipPolicy<T> {
public:
explicit SmartPtr(T* pointer);
SmartPtr(SmartPtr<T, OwnershipPolicy>& otherPointer);
SmartPtr<T, OwnershipPolicy> &operator=(SmartPtr<T, OwnershipPolicy>
&);


The above copy c'tor and operator= both take a reference to a SmartPtr
object. But references cannot be bound to temporaries, which you are
trying to do above. This is the reason, why the copy c'tor and the
operator= should both take /const/ references, because temporaries /can/
be bound to those.

ok, I do understand that, but I actually need them to be non-const, since I
do want to implement a destructive-copy, so SmartPtr(SmartPtr<T,
OwnershipPoliy& otherPointer) may change otherPointer. Any suggestions?
Jul 19 '05 #5
"Tobias Langner" <to************@t-online.de> wrote in message
news:bg*************@news.t-online.com...
Jakob Bieling wrote:
"Tobias Langner" <to************@t-online.de> wrote in message
news:bg*************@news.t-online.com...
compiling this line:

SmartPtr<LongWrapper, RefCount> p1=SmartPtr<LongWrapper, RefCount>(new
LongWrapper(1));
The above call creates a temporary SmartPtr object which is used to
copy
construct 'p1'.
with SmartPtr being:

template <class T, template <class> class OwnershipPolicy>
class SmartPtr : public OwnershipPolicy<T> {
public:
explicit SmartPtr(T* pointer);
SmartPtr(SmartPtr<T, OwnershipPolicy>& otherPointer);
SmartPtr<T, OwnershipPolicy> &operator=(SmartPtr<T, OwnershipPolicy>
&);


The above copy c'tor and operator= both take a reference to a SmartPtr object. But references cannot be bound to temporaries, which you are
trying to do above. This is the reason, why the copy c'tor and the
operator= should both take /const/ references, because temporaries /can/
be bound to those.

ok, I do understand that, but I actually need them to be non-const, since

I do want to implement a destructive-copy, so SmartPtr(SmartPtr<T,
OwnershipPoliy& otherPointer) may change otherPointer. Any suggestions?


Either do not use temporaries, or use a special function that implements
destructive copy, which the user has to call. Personally, I would go for the
special-method approach.

hth
--
jb

(replace y with x if you want to reply by e-mail)
Jul 19 '05 #6
Jakob Bieling wrote:
"Tobias Langner" <to************@t-online.de> wrote in message
news:bg*************@news.t-online.com...
Jakob Bieling wrote:
> "Tobias Langner" <to************@t-online.de> wrote in message
> news:bg*************@news.t-online.com...
>> compiling this line:
>>
>> SmartPtr<LongWrapper, RefCount> p1=SmartPtr<LongWrapper,
>> RefCount>(new
>> LongWrapper(1));
>
> The above call creates a temporary SmartPtr object which is used to
> copy
> construct 'p1'.
>
>> with SmartPtr being:
>>
>> template <class T, template <class> class OwnershipPolicy>
>> class SmartPtr : public OwnershipPolicy<T> {
>> public:
>> explicit SmartPtr(T* pointer);
>> SmartPtr(SmartPtr<T, OwnershipPolicy>& otherPointer);
>> SmartPtr<T, OwnershipPolicy> &operator=(SmartPtr<T, OwnershipPolicy>
>> &);
>
> The above copy c'tor and operator= both take a reference to a SmartPtr > object. But references cannot be bound to temporaries, which you are
> trying to do above. This is the reason, why the copy c'tor and the
> operator= should both take /const/ references, because temporaries
> /can/ be bound to those.
>

ok, I do understand that, but I actually need them to be non-const, since

I
do want to implement a destructive-copy, so SmartPtr(SmartPtr<T,
OwnershipPoliy& otherPointer) may change otherPointer. Any suggestions?


Either do not use temporaries, or use a special function that
implements
destructive copy, which the user has to call. Personally, I would go for
the special-method approach.

Actually I tried to implement different behaviour according to the
template-parameter OwnershipPolicy. If you create your SmartPointer<T,
RefCount>, you have a ref-counting one, if you create a SmartPointer<T,
DestructiveCopy>, you get one with destructive copy, if you create
SmartPointer<T, DeepCopy> you get one that does a deep copy. That would not
be possible with a special method.
Jul 19 '05 #7
"John Harrison" <jo*************@hotmail.com> wrote in message
news:bg************@ID-196037.news.uni-berlin.de...

"Jakob Bieling" <ne*****@gmy.net> wrote in message
news:bg*************@news.t-online.com...
"John Harrison" <jo*************@hotmail.com> wrote in message
news:bg************@ID-196037.news.uni-berlin.de...

"Tobias Langner" <to************@t-online.de> wrote in message
news:bg*************@news.t-online.com...
> compiling this line:
>
> SmartPtr<LongWrapper, RefCount> p1=SmartPtr<LongWrapper, RefCount>(new > LongWrapper(1));
>
> with SmartPtr being:
>
> template <class T, template <class> class OwnershipPolicy>
> class SmartPtr : public OwnershipPolicy<T> {
> public:
> explicit SmartPtr(T* pointer);
> SmartPtr(SmartPtr<T, OwnershipPolicy>& otherPointer);
> SmartPtr<T, OwnershipPolicy> &operator=(SmartPtr<T, OwnershipPolicy>
&);
> SmartPtr<T, OwnershipPolicy> &operator=(T*);
> ~SmartPtr();
> bool isNULL() { return pointer_==NULL; }
> T& operator*() const;
> T* operator->() const;
>
>
> private:
> void deleteObject();
> void copyPtr(SmartPtr<T, OwnershipPolicy>& otherPointer);
> void copyPtr(T* otherPointer);
> SmartPtr();
> T* pointer_;
>
> };
>
> i get the following error:
>
> test.cpp:22: no matching function for call to `SmartPtr<LongWrapper,
> RefCount>::SmartPtr(SmartPtr<LongWrapper, RefCount>)'
smartptr.h:105: > candidates are: SmartPtr<T, OwnershipPolicy>::SmartPtr(SmartPtr<T,
> OwnershipPolicy>&) [with T = LongWrapper, OwnershipPolicy = RefCount] >
> wich I don't understand.

Compiles fine for me once I've added dummy definitions for LongWrapper and RefCount. Post minimal, compilable code please.

Which compiler did you use? I did not compile it, since I was too

laze to add the dummy definitions, but as far as I can tell, it should not
compile. See my reply to the OP.


Right, I used that well known compiler which doesn't complain about
references to temporaries, VC++. Since I just upgraded to 7.1, I was

hoping that was fixed. I guess not.

It was. It is a so called 'languag extension'. Enable it, and you will
get the error, too. But then, unfortunately, the windows headers will not
compile anymore. I think the STL will, though.

regards
--
jb

(replace y with x if you want to reply by e-mail)
Jul 19 '05 #8

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

Similar topics

10
by: forgotten field | last post by:
Hi,how are you? I have been studying C++ by myself, but recently I am having a real problem. I am learning about the basic usage of a doubly linked list using polymorphism. However, I have got the...
19
by: Alf P. Steinbach | last post by:
// As usual the error message directs one to the report the bug. // // And as usual there is absolutely no way to do so without paying for // the privilege... // // Or using three or four hours...
22
by: Canonical Latin | last post by:
#include<iostream> int main() { char buff; std::cin.getline(buff,3); std::cin.getline(buff,3); std::cout << buff << endl; } Run at command prompt and input 1234567 what do you get as output?
16
by: pj | last post by:
(Was originally, probably wrongly, posted to the vc subgroup.) (This doesn't appear to be a c# problem, but a problem with a bug in the Visual Studio c# compiler, but, any help will be welcome...)...
9
by: JTrigger | last post by:
When I compile my project using the IDE on a development machine it works just fine. When I compile it on the server using csc.exe, I get the following error when I try to bring it up in the web...
11
by: zeppe | last post by:
Hi all, I've a problem. The code that follows creates a warning in both gcc and visual c++. However, I think it's correct: basically, there is a function that return an object of a derived...
0
by: erik.erikson | last post by:
I am getting a compiler error that I can't well explain or even understand the origin of (though I boiled it down close...). Below is a bare-bones example. What I am doing is defining the...
8
by: STG | last post by:
Greetings, My group has an SDK that was developed 5 years ago with VC++ 6. Over the last years, the requests for a VS.NET SDK has reached critical mass and I am now in the process of doing that....
6
by: Nathan Pinno | last post by:
Why does my compiler say invalid syntax and then highlight the quotation marks in the following code: # This program is to find primes. primes = import math import gmpy while 1: run =...
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
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
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...
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
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...

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.