473,396 Members | 2,002 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,396 software developers and data experts.

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

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<inttoolfn(TA<T>& obj);

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

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

public:
friend TA<inttoolfn<T>(TA<T>& obj);
};
template<typename T>
TA<inttoolfn(TA<T>& obj)
{
return TA<int>( fn(obj) );
}

int main()
{
TA<floatf1;
TA<intret = toolfn(f1);//----->how to make it pass the compiling.
/*
compiling error:
1.cpp: In function `TA<inttoolfn(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

Jun 27 '08 #1
1 1033
declare the whole template as friend...
Jun 27 '08 #2

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

Similar topics

23
by: sashan | last post by:
I'm a Python newbie. I have been using c++ for 5 years and before that I was programming in Pascal. The one thing that annoys me about python is dynamic typing because I find myself making...
5
by: Kirk Job-Sluder | last post by:
Hrm, I'm a bit stumped on this. I want to write a script lists a file directory hierarchy and gives me a sorted list showing cumulative directory size. The example code for os.walk gets me...
0
by: Frans Englich | last post by:
Hello, Have a look at this recursive function: def walkDirectory( directory, element ): element = element.newChild( None, "directory", None ) # automatically appends to parent...
5
by: verec | last post by:
I just do not understand this error. Am I misusing dynamic_cast ? What I want to do is to have a single template construct (with no optional argument) so that it works for whatever T I want to...
26
by: Michael McGarry | last post by:
Hi, I am pretty sure this is not possible, but maybe somehow it is. Given a variable, can I tell what type it is at runtime? Michael
17
by: Mike Hofer | last post by:
While I'd toyed with C, C++, and Java over the last 20 years or so, my principal language has been BASIC, QBASIC, then Visual Basic, and finally Visual Basic .NET. But lately, I've been using C#...
9
by: silverburgh.meryl | last post by:
i am trying to use python to walk thru each subdirectory from a top directory. Here is my script: savedPagesDirectory = "/home/meryl/saved_pages/data" dir=open(savedPagesDirectory, 'r') ...
1
by: Dabulsta | last post by:
Hi Does anyone know were I can get some type of walk through? I am trying to set up a network from scratch (Physical, Logically) within server 2003???? any suggestions!!!
2
by: Martin Marcher | last post by:
Hello, I'm playing around with os.walk and I made up del_tree(path) which I think is correct (in terms of the algorithm, but not as python wants it :)). As soon as some directory is deleted...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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...

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.