C++ template - type/value mismatch at argument -
this question has answer here:
i getting these errors,
type/value mismatch @ argument 1 in template parameter list ‘template class sasenginequeue’
type/value mismatch @ argument 2 in template parameter list ‘template class sasenginequeue’
but if use template arguments of sasenginequeue class std::string, ok, code below if use std::vector, there errors. why?
class sasengine{ private: unsigned char addr; sasenginequeue<std::vector, std::vector> sasq; sastcp_ip sastransport; };
template<typename exception_t, typename lp_t> class sasenginequeue{ public: threadsafequeue<exception_t> exceptionq; threadsafequeue<lp_t> lpcmdq; threadsafequeue<lp_t> lprspq; };
template<typename msgtype> class threadsafequeue{ protected: queue<msgtype> threadsafeq; mutex mu; public: int get(msgtype& msg); void push(msgtype msg); void pop(); };
template<typename msgtype> int threadsafequeue<msgtype>::get(msgtype& msg){ lock_guard<mutex> automutex(mu); if(threadsafeq.empty()){ //empty queue return -1; } msg = threadsafeq.front(); return 0; } template<typename msgtype> void threadsafequeue<msgtype>::push(msgtype msg){ lock_guard<mutex> automutex(mu); threadsafeq.push(msg); } template<typename msgtype> void threadsafequeue<msgtype>::pop(){ lock_guard<mutex> automutex(mu); threadsafeq.pop(); } template int threadsafequeue<std::vector>::get(std::vector& msg); template void threadsafequeue<std::vector>::push(std::vector msg); template void threadsafequeue<std::vector>::pop(); template int threadsafequeue<std::string>::get(std::string& msg); template void threadsafequeue<std::string>::push(std::string msg); template void threadsafequeue<std::string>::pop();
you should point out error occurring - makes lot easier people trying answer.
anyway, issue while std::string
type (specifically, typedef std::basic_string<char>
), std::vector
isn't. it's template, , need specify type vector contains, e.g. std::vector<int>
.
you might want make work vector - unfortunately, doesn't work, because explicit instantiations have specify concrete type.
Comments
Post a Comment