c++ - glm 和 cxx-prettyprint,clang : call to function 'operator <<' that is neither visible in the template definition

标签 c++ c++11 clang libc++ glm-math

有人一起使用这些库吗? 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) {
         ^

最佳答案

这是将它放入命名空间的方法。修正了我的错误。

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

关于c++ - glm 和 cxx-prettyprint,clang : call to function 'operator <<' that is neither visible in the template definition,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18546939/

相关文章:

C++、信号和线程

C++11 "Non-movable"类型

c++ - 在多个编译单元中使用的 C++ 库导致链接器错误

C++释放指向作为线程lpParam传递的结构的指针内部的指针

c++ - C++CLI 的 *var* 关键字

c++ - 通过引用传递 Complex real 和 imag

c++ - 使用字符串文字在构造函数中初始化 std::array<char,x> 成员。海湾合作委员会错误?

linux - 使用 clang++ 时默认启用 libc++/libcxx

c++ -/usr/bin/ld : cannot find -lcaffe

c++ - 类无法访问其自己的私有(private)静态 constexpr 方法 - Clang 错误?