Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > construct a new type obj failed---how to walk around it...

Reply
Thread Tools

construct a new type obj failed---how to walk around it...

 
 
kuangye
Guest
Posts: n/a
 
      06-25-2008
Hi, all.

///////////////////////////////////
////////code sample
/////compiling error in vs2005 and gcc3.4
///////////////////////////////////
class CB;

CB fn(CB& obj);

class CB
{
protected:
CB(){}
CB(const CB& ob){}

friend CB fn(CB& obj);
};

CB fn(CB& obj)
{
return CB();
}

//////////////////////////////////////
template<typename T>
class TA;

template<typename T>
TA<int> toolfn(TA<T>& obj);

template<typename T>
class TAublic CB
{
template<typename U>
friend class TA;

public:
TA(){};
protected:
//should be protected or private
TA(const CB& ob):CB(ob){}

public:
friend TA<int> toolfn<T>(TA<T>& obj);
};


template<typename T>
TA<int> toolfn(TA<T>& obj)
{
return TA<int>( fn(obj) );
}

int main()
{
TA<float> f1;
TA<int> ret = toolfn(f1);//----->how to make it pass the compiling.
/*
compiling error:
1.cpp: In function `TA<int> toolfn(TA<T>&) [with T = float]':
1.cpp:52: instantiated from here
1.cpp:36: error: `TA<T>::TA(const CB&) [with T = int]' is protected
1.cpp:46: error: within this context
*/

return 0;
}

////////////////////////////////////////////
///currently, i can using a helper function to walk around this
//but it seems that it does not elegant enough...
///////////////////////////////

Any hint will be appreciated

 
Reply With Quote
 
 
 
 
kuangye
Guest
Posts: n/a
 
      06-26-2008
declare the whole template as friend...
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Behavior of if construct in switch case defualt construct. Mukesh C Programming 4 03-26-2010 12:38 PM
isinstance(obj, type(obj)) == True? Art Python 2 06-24-2009 06:31 PM
Obj* ptr = new Obj(X) Phil Endecott C++ 5 06-03-2005 10:48 PM
Descriptors: why __get__(obj,typ=None) instead of __get__(obj,typ) Shalabh Chaturvedi Python 2 02-20-2004 08:26 PM
difference between Convert.ToString(obj) and CType(obj, String) Mark Kamoski ASP .Net 3 08-08-2003 11:09 PM



Advertisments