c++11 - Returning different template specialisations from a function -


i have created c++11 class in want parse string , return object based on data in string. object want return defined as:

 // container topic data , id template <typename t>  class topic { public:   topic(string id, t data)   : _id(id), _data(data)   {}  private:   string _id;   t _data; }; 

the function returns object defined as:

// parses string , splits components

class topicparser { public:   template <class t>   static topic<t>   parse(string message)   {     t data; // string, vector<string> or map<string, string>     string id = "123";     topic<t> t(id, data);     return t;   }   }; 

i (think i) able call function in way:

string message = "some message parse..."; auto = topicparser::parse<topic<vector<string>>>(message); auto b = topicparser::parse<topic<string>>(message); 

but compiler complains that:

no matching function call ‘topic<std::vector<std::basic_string<char> > >::topic()’ 

as can tell, i'm not templates expert. i'm trying approved way of using templates of should prefer other method?

using topic<vector<string>> template argument useless here, guess. remove topic:

auto = topicparser::parse<vector<string>>(message); auto b = topicparser::parse<string>(message); 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -