Hogeのコピーコンストラクタが呼ばれてほしいのですが、テンプレート版の方が呼ばれてしまいます。
何かスマートな解決法はないでしょうか?
class Hoge
{
public:
template <class T>
explicit Hoge(T& val) { cout << "template" << endl; }
Hoge(const Hoge& other) { cout << "copy ctor" << endl; }
};
class Piyo
{
public:
template <class T>
Piyo(T& val)
: ptr(new T(val)) // コピーコンストラクタ呼び出しのつもりが、呼ばれない
{}
private:
shared_ptr<void> ptr;
};
int main()
{
int forTemplate = 123;
Hoge hoge( forTemplate ); // テンプレート版コンストラクタをよぶ
Piyo piyo( hoge ); // hogeを内部でコピーして保持したい
return 0;
}