#include<stdlib.h>
#include<iostream>
using namespace std;
class CB;
class CA;
template <class P>
class RefCounted
{
public:
RefCounted()
:pCount_(0)
{};
RefCounted(const RefCounted& rhs)
: pCount_(rhs.pCount_)
{}
// MWCW lacks template friends, hence the following kludge
template <typename P1>
RefCounted(const RefCounted<P1>& rhs)
: pCount_(reinterpret_cast<const RefCounted&>(rhs).pCount_+1)
{}
protected:
unsigned int pCount_;
};
template< class U, template< class > class someclass >
class TTC : public someclass< U >
{
public:
TTC()
{
cout<<"TTC()"<<endl;
};
template< class U1, template< class > class anyclass >
TTC( const TTC< U1, anyclass >& rhs )
{
cout<<"In TTC< U, someclass >( TTC< U1, anyclass > )"<<endl;
}
};
/*
class TTC< CA, RefCounted >
{
public:
TTC()
{
cout<<"TTC<A>()"<<endl;
};
TTC( const TTC< CB, RefCounted >& rhs )
{
cout<<"In TTC< CA, RefCounted >"<<endl;
}
};
class TTC< CB, RefCounted >
{
public:
TTC()
{
cout<<"TTC<B>()"<<endl;
};
TTC( const TTC< CA, RefCounted >& rhs )
{
cout<<"In TTC< CB, RefCounted >"<<endl;
}
};
*/
class CB
{
};
class CA
{
};
int main()
{
TTC< CB, RefCounted > b;
TTC< CA, RefCounted > a( b );
TTC< CB, RefCounted > ba( a );
system("pause");
return 0;
}
请教各位大虾,现在编译通不过(因为 TTC拷贝构造函数无效),加上被注释的程序后就可通过编译(我用的dev-cpp),请问如何修改
template< class U1, template< class > class anyclass >
TTC( const TTC< U1, anyclass >& rhs )
{
cout<<"In TTC< U, someclass >( TTC< U1, anyclass > )"<<endl;
}
这个模板拷贝构造函数,从而不加被注释的程序可使这个拷贝构造函数有效。