By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,897 Members | 1,955 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,897 IT Pros & Developers. It's quick & easy.

SmartPointer & User Conversion & Sucking Compiler

P: n/a
MS VS 7.0 happily resolves by SmartPointer and Inheritance, but I got
to use another target compiler and it does not accept user conversion
for templates. Can I forced a recast somehow? I have judiciously
checked almost all constructs with both compiler before coding, but
during a heavy session, I forgot to check the user conversion part,
and now, I am stuck big time :(

So here is my user conversion for a smart pointer class (direct from
Scott Meyer) :)

public:
template<class aNewTypeoperator SmartPointer<aNewType>()
{
return SmartPointer<aNewType>(pointee);
}

For example,

Class Person;
Class Employee : Person
Class Student : Person

SmartPointer<Personp;
SmartPointer<Employeee;
SmartPointer<Students

p = e; // "Ambigous user conversion"

Can I safely force the recast? I have only 1-level of inheritance,
so maybe there is a quick rewrite that is safe?

Thanks,

Jun 12 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On Jun 11, 11:04 pm, coder_...@yahoo.com wrote:
MS VS 7.0 happily resolves by SmartPointer and Inheritance, but I got
to use another target compiler and it does not accept user conversion
for templates. Can I forced a recast somehow? I have judiciously
checked almost all constructs with both compiler before coding, but
during a heavy session, I forgot to check the user conversion part,
and now, I am stuck big time :(

So here is my user conversion for a smart pointer class (direct from
Scott Meyer) :)

public:
template<class aNewTypeoperator SmartPointer<aNewType>()
{
return SmartPointer<aNewType>(pointee);
}

For example,

Class Person;
Class Employee : Person
Class Student : Person

SmartPointer<Personp;
SmartPointer<Employeee;
SmartPointer<Students

p = e; // "Ambigous user conversion"

Can I safely force the recast? I have only 1-level of inheritance,
so maybe there is a quick rewrite that is safe?

Thanks,

I thought of something dirt ugly. Since my refcount is in the base
class P, I could just do the following:

SmartPointer<Personp(s.getPointee);

Ugly, but that should be safe...?!?

Jun 12 '07 #2

P: n/a
Do you have any template constructors for SmartPointer?
Constructors are included in C++ automatic type conversion system.
The error the you are most likely to be getting is where there is more
than on conversion path between to types.
I bet some constructor the auto type conversion system is trying to
use in the SmartPointer template class.

Thats my thought
On Jun 11, 11:04 pm, coder_...@yahoo.com wrote:
MS VS 7.0 happily resolves by SmartPointer and Inheritance, but I got
to use another target compiler and it does not accept user conversion
for templates. Can I forced a recast somehow? I have judiciously
checked almost all constructs with both compiler before coding, but
during a heavy session, I forgot to check the user conversion part,
and now, I am stuck big time :(

So here is my user conversion for a smart pointer class (direct from
Scott Meyer) :)

public:
template<class aNewTypeoperator SmartPointer<aNewType>()
{
return SmartPointer<aNewType>(pointee);
}

For example,
Class Person;
Class Employee : Person
Class Student : Person

SmartPointer<Personp;
SmartPointer<Employeee;
SmartPointer<Students

p = e; // "Ambigous user conversion"

Can I safely force the recast? I have only 1-level of inheritance,
so maybe there is a quick rewrite that is safe?

Thanks,

Jun 12 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.