xcode - Xcode7: unknown type name error in a basic C++ program -
i working on c++ program stl latest version of xcode, , error "unknown type name 'ubresultdata'" , "unknown type name 'ubfirstargument'". have tried rewrite program standard unary_function , binary_function, , errors remained same. then, build progaram vs2010 , vs2013, , built successfully. what's wrong program?
the errors in last line of class binder2nd.
#include <iostream> #include <vector> using namespace std; template<typename inputiterator, typename predicator> inline int countif(inputiterator first, inputiterator last, predicator pred){ int count = 0; (; first != last; ++first) { if(pred(*first))++count; } return count; } template<typename arg1, typename result> struct unarybase{ typedef arg1 ubfirstargument; typedef result ubresultdata; }; template<typename arg1, typename arg2, typename result> struct binarybase{ typedef arg1 bbfirstargument; typedef arg2 bbsecondargument; typedef result bbresultdata; }; template<typename t> struct less:public binarybase<t, t, bool>{ bool operator()(const t& left, const t& right)const{ return (left < right); } }; template<typename binop> class binder2nd:public unarybase<typename binop::bbfirstargument, typename binop::bbresultdata>{ protected: binop op; typename binop::bbsecondargument arg2; public: binder2nd(const binop& oper, const typename binop::bbsecondargument& valright):op(oper),arg2(valright){} ubresultdata operator()(const ubfirstargument &ubarg1)const{return op(ubarg1,arg2);} }; template<typename binop, typename rightval> binder2nd<binop> bind2nd(const binop& op, const rightval& vright){ return binder2nd<binop>(op, vright); } int main(){ vector<int> myvec; (int = 0; < 50; ++i) { myvec.push_back(rand()%100); } int countnum = countif(myvec.begin(), myvec.end(), bind2nd(less<int>(), 30)); cout << "numbers=" << countnum << endl; return 0; }
i don't remember exact phrasing standard, here's simplified code demonstrates same behavior yours:
template <typename t> struct { typedef t x; }; template <typename t> struct b: public a<t> { x x(void) { return 5; } };
and here's version compiles without errors:
template <typename t> struct { typedef t x; }; template <typename t> struct b: public a<t> { typename a<t>::x x(void) { return 5; } };
so basically, need specify type comes from.
it looks vs* compilers bit more permissive gcc or clang. :)
Comments
Post a Comment