function template application in class

#include <iostream>
#include <string>
using namespace std;

class ConfigTest
{
public:
 ConfigTest()
 {
  std::cout<<"Config constructor...."<<std::endl;
 }
 template<typename T>
 T value( std::string key, T fallback ) const {
  std::string r = "feier";
  return r;
 }
 template<typename T>
 T getIfSet( std::string key, T output ) const {
  if ( key == "haces" ) {
   T cc = value<T>(key, output);
   return cc;
  }
  return false;
 }
};
void main()
{
 /** the follow line is error!  this is not class template,but function template in class*/
 //Config<std::string> testConfig;
 ConfigTest testConfig;
 std::string in = "haces";
 std::string outputStr = "qq";
 std::string testBool = testConfig.getIfSet(in,outputStr);
 std::cout<<testBool<<endl;
 system("pause");
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章