2
是否有任何方式获取C++构造函数的参数?获取类的构造函数参数
template <typename T>
class Test {
public:
// Get the constructor arguments from class T
Test(constructor<T>());
private:
T* value_;
};
template <typename T>
Test(constructor<T>()) {
value_ = new T(constructor);
}
int main() {
// std::string can be initialized by string literal
Test<std::string> test("Text");
return 0;
}
我知道我可以只使用T
的说法,但我并不想通过对象本身,只是它需要的参数。
无论如何在标准C++中做到这一点?
[C++获取构造函数的类型]的可能副本(http://stackoverflow.com/questions/41623899/c-obtaining-the-type-of-a-constructor) –
是[this](http: //ideone.com/GvbUyX)你在找什么? –