64,654
社区成员
发帖
与我相关
我的任务
分享
struct loop_compare_method{
static void execute();
}
struct other_method {
static void execute;
}
template<bool>
smart_method {
typedef loop_compare_method real_method;
}
template <>
smart_method<false> {
typedef other_method real_method;
}
// 调用方法:
smart_method<这里填写根据上面的帖子判断有没有lengh函数的代码>::real_method::execute()
/// A and B's definition are fixed.
struct A{
int x(){return 1;};
};
struct B{
int y(){return 0;};
};
// function i should implement
////////////////////////////////////////
template<typename T>
struct Func(const T& p){
/// do something with A
}
template<typename T>
struct Func(const T& p){
/// do something with B
}
////////////////////////
A a;
B b;
Func(a); /// 我想要这个调用第一个Func
Func(b); /// 我想要这个调用第二个Func
struct里可以带函数的。
struct myStruct{
//默认为public的
myStruct(int d):data(d){}
myStruct(const myStruct &mySt){...}
int getData(){ return data;}
private:
int data;
};