2013-08-31 25 views
2

有沒有人使用這些庫? cxx-prettyprintglm。我遇到了一個難以理解的編譯時問題。glm和cxx-prettyprint,clang:調用在模板定義中不可見的函數'operator <<'

9 #include "Math.h" 
    10 #include "UnitTestConfigurator.h" 
    11 #include <vector> 
    12 using namespace std; 
    13 
    14 ostream& operator <<(ostream& os, const v3& v) { 
    15  string s("a v3"); 
    16  os << s; 
    17  return os; 
    18 } 
    19 
    20 SUITE(MathTests) { 
    21  TEST(PrintVectorType) { 
    22   v3 vec3; 
    23   cout << vec3; 
    24  } 
    25  TEST(PrintVectorofVectors) { 
    26   vector<v3> v; 
    27   cout << v; 
    28  } 
    29 } 

如果你被「組曲」和「TEST」混爲一談,這是因爲該代碼使用UnitTest++

MATH.H中有:

# include "../glm/glm/glm.hpp" 
typedef glm::vec2 v2; 
typedef glm::vec3 v3; 

這裏的錯誤:

In file included from Math.cpp:10: 
In file included from ./UnitTestConfigurator.h:26: 
In file included from ./util.h:62: 
./prettyprint.hpp:212:32: error: call to function 'operator<<' that is neither visible in the 
     template definition nor found by argument-dependent lookup 
         stream << *it; 
          ^
./prettyprint.hpp:295:9: note: in instantiation of member function 
     'pretty_print::print_container_helper<std::__1::vector<glm::detail::tvec3<float, 0>, 
     std::__1::allocator<glm::detail::tvec3<float, 0> > >, char, 
     std::__1::char_traits<char>, 
     pretty_print::delimiters<std::__1::vector<glm::detail::tvec3<float, 0>, 
     std::__1::allocator<glm::detail::tvec3<float, 0> > >, char> >::operator()' requested 
     here 
     helper(stream); 
     ^
./prettyprint.hpp:305:23: note: in instantiation of function template specialization 
     'std::operator<<<std::__1::vector<glm::detail::tvec3<float, 0>, 
     std::__1::allocator<glm::detail::tvec3<float, 0> > >, char, 
     std::__1::char_traits<char>, 
     pretty_print::delimiters<std::__1::vector<glm::detail::tvec3<float, 0>, 
     std::__1::allocator<glm::detail::tvec3<float, 0> > >, char> >' requested here 
     return stream << ::pretty_print::print_container_helper<T, TChar, TCharTraits... 
        ^
Math.cpp:27:8: note: in instantiation of function template specialization 
     'std::operator<<<std::__1::vector<glm::detail::tvec3<float, 0>, 
     std::__1::allocator<glm::detail::tvec3<float, 0> > >, char, std::__1::char_traits<char> 
     >' requested here 
       cout << v; 
        ^
Math.cpp:14:10: note: 'operator<<' should be declared prior to the call site or in namespace 
     'glm::detail' 
ostream& operator <<(ostream& os, const v3& v) { 
     ^
+0

嗯,最後一個clang錯誤提示看起來很清楚我的'operator <<'應該如何在其他名字空間中定義 –

回答

1

這是如何把它的命名空間。修正了我的錯誤。

namespace glm { namespace detail { 
    ostream& operator <<(ostream& os, const v3& v) { 
     os << v.x << v.y << v.z; // super crappy implementation! 
     return os; 
    } 
}} 
相關問題