64,648
社区成员
发帖
与我相关
我的任务
分享
class BBB:public PPP
{
public:
BBB(M& m);
public:
void Handle(){//M related operation};
}
class CCC: public PPP
{
public:
CCC(N& n);
public:
void Handle(){//N related operation};
}
class DDD : public PPP
{
public:
DDD(T& t);
public:
void Handle(){//N related operation};
}
template<typename T>
void Handle(T&& t){
t.Handle();
}
template<typename M>
class BBB//:public PPP
{
public:
BBB(M& m);
public:
void Handle(){//M related operation};
}
template<typename N>
class CCC//: public PPP
{
public:
CCC(N& n);
public:
void Handle(){//N related operation};
}
template<typename T>
class DDD //: public PPP
{
public:
DDD(T& t);
public:
void Handle(){//N related operation};
}
template<typename T>
DDD<T> makeDDD(T& t){
return DDD(t);
}
std::string s = "hello";
Handle(makeDDD(s));
int a = 5;
Handle(makeDDD(a));
#include <iostream>
template <class _Tp>
class Sometype
{
public:
void Handle() { std::cout << "General handler\n"; }
private:
_Tp data_;
};
template <> void Sometype<int>::Handle()
{
std::cout << "int handler\n";
}
template <> void Sometype<double>::Handle()
{
std::cout << "double handler\n";
}
int main ()
{
Sometype<char> inst0;
Sometype<int> inst1;
Sometype<double> inst2;
inst0.Handle();
inst1.Handle();
inst2.Handle();
return 0;
}
Output
C:\Users\WJJ\Desktop>g++ -g -Wall test.cpp
C:\Users\WJJ\Desktop>a.exe
General handler
int handler
double handler