c++ - Is there an implicit template<typename T>operator<<(const ostream&,T)? -
i have class i've written, meant represent vectors (in linear algebra sense). started writing isn't finished, i've pasted , test code here
i'm not sure what's going on. going write overloaded operator<< testing in second, went ahead , put in main function (so use compiler errors make sure i'd written properly).
what warning mean? why looking @ address of v? tried removing parentheses v, , end this, bunch of horrible template errors: `
in function 'typename boost::range_const_iterator<c>::type boost::range_detail::boost_range_begin(const c&) [with c = vect<float, 3u>]': /usr/local/include/boost/range/begin.hpp:164: instantiated 'typename boost::range_const_iterator<c>::type boost::begin(const t&) [with t = vect<float, 3u>]' prelude/more_stdlib_ostreaming.hpp:64: instantiated 'void more_stdlib_ostreaming_detail::print_range(std::basic_ostream<_chart, _traits>&, const range&) [with c = char, tr = std::char_traits<char>, range = vect<float, 3u>]' prelude/more_stdlib_ostreaming.hpp:76: instantiated 'typename more_stdlib_ostreaming_detail::snd<typename r::iterator, std::basic_ostream<_chart, _traits>&>::type operator<<(std::basic_ostream<_chart, _traits>&, const r&) [with c = char, tr = std::char_traits<char>, r = vect3f]' t.cpp:42: instantiated here line 45: error: 'const class vect<float, 3u>' has no member named 'begin'` i can sort of see whats going on here, tho. looks somehow using boost's range , trying iterate on container, , failing because haven't defined begin() , end(). same thing happens if instantiate v using v(some_float) rather without parens.
so, 2 questions:
why
v()behaving differentlyv? thought declaring object without parens calls default ctor anyway, , explicitly calling default ctor made no difference?what codepad's compiler (gcc 4.1.2) doing here? have template automatically tries generate appropriate operator<
also, feel free tell me else i'm doing stupid/wrong/bad style here (besides rolling own matrix math library fun, know unnecessary. i'm doing exercise)
first of all, vect3f v(); declares function (named v), taking no parameters , returning vect3f. , operator<< being called called function pointer (which implicitly converted bool, because there's no overload function pointers).
vect3f v; correct way of creating default-constructed object.
and no, compiler won't try generate ostream& operator<<(ostream& /* ... */) you. there many overloads fundamental types , other types (such std::string).
you can check basic overloads here.
Comments
Post a Comment