 |
|
aglargilwangz
V2EX member #436823, joined on 2019-08-19 16:01:12 +08:00
|
 |
Per aglargilwangz's settings, the topics list is hidden |
Deals info, including closed deals, is not hidden
aglargilwangz's recent replies
```cpp
#include <iostream>
struct Base {
void print() {
std::cout << "Base class\n";
}
};
struct Str : Base {
Str(const char* s) {}
void print() {
std::cout << "String class\n";
}
};
struct Num : Base {
Num(int v) {}
void print() {
std::cout << "Number class\n";
}
};
template<typename T>
struct Mapper;
template<>
struct Mapper<const char*> {
using type = Str;
};
template<>
struct Mapper<int> {
using type = Num;
};
template<typename T>
void log(T obj) {
typename Mapper<T>::type mappedObj(obj);
mappedObj.print();
}
int main() {
log("hello");
log(123);
}
```
hi,楼主,我也有跟你类似的想法,方便加个联系方式细聊吗