2

有人一起使用这些库吗?cxx-prettyprintglm。我遇到了一个很难弄清楚的编译时问题。

    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 }

如果您对“SUITE”和“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) {
         ^
4

1 回答 1

1

这是如何将其放入命名空间中的。修正了我的错误。

namespace glm { namespace detail {
    ostream& operator <<(ostream& os, const v3& v) {
        os << v.x << v.y << v.z; // super crappy implementation!
        return os;
    }
}}
于 2013-08-31T10:13:27.060 回答