-2
次のプログラムの実行中にコンパイルの問題が発生しています: テンプレートメンバ関数内で非テンプレートメンバ関数を呼び出していますが、奇妙なコンパイルエラーが発生します。すべてのヘルプは理解されるであろうテンプレートメンバ関数内で非テンプレートメンバ関数を呼び出す
Error 1 error C2664: 'base::fun3' : cannot convert parameter 1 from 'boost::shared_ptr<T>' to 'boost::shared_ptr<T> &'
:
#include <iostream>
#include <boost\shared_ptr.hpp>
class base
{
public:
base()
{
}
void fun2(boost::shared_ptr<int> &data)
{
std::cout << "This is fun2" << std::endl;
}
void fun3(boost::shared_ptr<double> &value)
{
std::cout << "This is fun3" << std::endl;
}
template <typename T>
void fun1(int switchParam,T &resonse)
{
std::cout << "This is fun1." << std::endl;
switch(switchParam)
{
case 0:
fun2(resonse);
break;
case 1:
fun3(resonse);
break;
}
}
};
void main()
{
boost::shared_ptr<int> myInt;
int switchParam = 0;
base b1;
b1.fun1(switchParam,myInt);
}
次のコンパイルの問題を取得します。
'fun3'は' double'へのポインタを期待しています。あなたは 'int'へのポインタを渡してコンパイルしようとしています。それについて何が奇妙ですか? – imreal
私はfun1に異なるデータ型を渡したいと思いますが、ケースの条件によってはそれに応じて異なる関数を呼び出す必要があります。 – Sumeet
私はshared_ptrを渡さずに、intやdoubleのようなデフォルトのデータ型を使うと同じことができます。 – Sumeet