小编Gil*_*les的帖子

类模板构造函数中的SFINAE

我正在尝试用模板和SFINAE制作一些东西,我是初学者.我浪费了大量的时间来完成最简单的工作.你能帮我理解它的工作原理吗?

C <T,Ts ...>的构造函数采用T参数,该参数是A <U>或B <U>,但在这两种情况下具有不同的行为.我无法告诉你我试图这么做的一切.这对我来说似乎是最不愚蠢的.

template<typename T> class A{
public: A(){} };

template<typename T> class B{
public: B(){} };

template<typename T> struct enable_if_A         {};
template<typename T> struct enable_if_A< A<T> > {typedef A<T> type;};

template<typename T> struct enable_if_B         {};
template<typename T> struct enable_if_B< B<T> > {typedef B<T> type;};

template<typename T,typename... Ts> class C{
public:
    C(typename enable_if_A<T>::type const &p){cout << "A" << endl;}
    C(typename enable_if_B<T>::type const &p){cout << "B" << endl;}
};

// ...

A<float> a;
B<float> b;

C<A<float> > ca(a); …
Run Code Online (Sandbox Code Playgroud)

c++ constructor sfinae c++11 template-classes

3
推荐指数
1
解决办法
1317
查看次数

glew.h 和 glext.h 之间不兼容的函数原型

我正在尝试使用 glew.h 和 glext.h 编译一些代码。这是一个最小的例子:

#include <GL/glew.h>
//#include <GL/gl.h> // commenting it doesn't change anything
#include <GL/glext.h>

int main(){
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

由于不同的函数原型,我有 6 个编译时错误。第一个是:

In file included from main.cpp:3:0:
/usr/include/GL/glext.h:12306:105: error: conflicting declaration ‘typedef void (* PFNGLFRAGMENTLIGHTFVSGIXPROC)(GLenum, GLenum, const GLfloat*)’
 typedef void (APIENTRYP PFNGLFRAGMENTLIGHTFVSGIXPROC) (GLenum light, GLenum pname, const GLfloat *params);
                                                                                                         ^
In file included from main.cpp:1:0:
/usr/include/GL/glew.h:16092:28: note: previous declaration as ‘typedef void (* PFNGLFRAGMENTLIGHTFVSGIXPROC)(GLenum, GLenum, GLfloat*)’
 typedef void (GLAPIENTRY * PFNGLFRAGMENTLIGHTFVSGIXPROC) (GLenum light, GLenum pname, GLfloat* params); …
Run Code Online (Sandbox Code Playgroud)

c++ opengl glew

3
推荐指数
1
解决办法
151
查看次数

标签 统计

c++ ×2

c++11 ×1

constructor ×1

glew ×1

opengl ×1

sfinae ×1

template-classes ×1