1
templatized 인수에 따라 적절한 형식을 반환해야합니다. 아래 오류가 발생합니다. 누군가 제안 할 수 있습니까? ? 사전에 이에 대한 해결책은 감사오류 : 두 번째 :: 두 번째 호출에 대한 일치하는 함수가 없습니다. 두 번째 :: 초 (
error: no matching function for call to âsecond::second(const std::basic_string<char,
std::char_traits<char>, std::allocator<char> >&)â
note: candidates are: second::second(const std::string&, const std::string&)
note: second::second(const second&)
코드는 다음과 같습니다 :.
struct first
{
public:
const string &str;
first(const string & str) : str(str) { }
};
struct second : public first
{
public:
const string &str2;
second(const string &str1, const string &str2) : first(str1), str2(str2)
{ }
};
class base
{
public:
template<class T>
inline T fun(const string &s1, const string &s2);// { cout<<" T = "<<a; }
};
template<class T>
inline T base::fun(const string &s1, const string &s2)
{
if(1)
return T(s1);
else
return T(s1, s2);
}
int main()
{
string a = "a";
string bb = "b";
base b;
b.fun<first>(a, bb);
b.fun<second>(a, bb);
return 0;
}
기능'기본 :: fun' 모든 유형의 'T'에 대해 컴파일 할 수 있어야합니다. 당신이하고 싶은 것을 성취하기 위해서는'base :: fun'를 전문화해야 할 것입니다. – Niall