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

SmartPointer & User Conversion & Sucking Compiler

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
2 1659
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Tobias Kilian | last post by:
Hi Ng ! I wrote a SmartPointer class which holds a doubled linked list to all its copies to ensure that all copies are holding the same pointer, even if one copy changes later. If the last...
15
by: mathieu | last post by:
Hi, I have implemented a SmartPointer class following the implementation proposed by Bill Hubauer(*). But I also override the operator * () template<class ObjectType> class SmartPointer {...
10
by: lovecreatesbeauty | last post by:
Is parameter type conversion required for the 2nd argument on printf("%p", (void *)&i); ? But one would never call memcpy like: memcpy((void *)pi, (void *)pj, sizeof *pj); /*memcpy((void *)pi,...
4
by: arnuld | last post by:
i am learning C and doing the exercise 1-1 of K&R2, where K&R ask to remove some parts of programme and experiment with error, so here i go: #include <stdio.h> int main () { printf('hello...
1
by: developereo | last post by:
Hi folks, Can somebody shed some light on this problem? class Interface { protected: Interface() { ...} virtual ~Interface() { ... } public:
42
by: coder_lol | last post by:
Thanks everyone again for contributing to helping me clear C++ confusions. I did some serious reading on copy constructors and assignments and I think I've got a good handle on the memory stuff. ...
0
by: paalkrebs | last post by:
I've made two smartpointers that I'd like to share. Improvements and comments are welcome. The key to both is that there should be no access to the managed object, and all operations should be...
3
by: Martin T. | last post by:
Hello. I tried to overload the operator<< for implicit printing of wchar_t string on a char stream. Normally using it on a ostream will succeed as std::operator<<<std::char_traits<char> will...
82
by: arnuld | last post by:
PURPOSE :: see statement in comments GOT: Segmentation Fault I guess the segfault is sourced in the compile-time warning but I am giving a char* to the function already.
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.