Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 错误:常量返回类型的转换无效_C++_C_C++11_G++ - Fatal编程技术网

C++ 错误:常量返回类型的转换无效

C++ 错误:常量返回类型的转换无效,c++,c,c++11,g++,C++,C,C++11,G++,使用g++版本4.8.4,我得到一个错误: 错误:从'const SSL_METHOD*{aka const SSL_METHOD_st}'到'MethodFuncPtr{aka SSL_METHOD_st*}'[-fppermissive]的转换无效 我可以使用-fppermissive进行编译,但什么是修复?我见过这种类型错误的解决方案,但是当返回类型为const时,没有解决方案,即使它显式地是一个const返回值 ssl.h C头中的一个片段: #ifdef __cplusplus ex

使用g++版本4.8.4,我得到一个错误:

错误:从'const SSL_METHOD*{aka const SSL_METHOD_st}'到'MethodFuncPtr{aka SSL_METHOD_st*}'[-fppermissive]的转换无效

我可以使用-fppermissive进行编译,但什么是修复?我见过这种类型错误的解决方案,但是当返回类型为const时,没有解决方案,即使它显式地是一个const返回值

ssl.h C头中的一个片段:

#ifdef  __cplusplus
extern "C" {
#endif

  typedef struct ssl_method_st {
    int version;
    int (*ssl_new) (int *s);
    void (*ssl_clear) (int *s);
  } SSL_METHOD;

  const SSL_METHOD *TLSv1_method(void);

#ifdef  __cplusplus
}
#endif
C++标题:

#include <ssl.h>

extern "C" {
  typedef SSL_METHOD*(*MethodFuncPtr)(void);
}

class Method
{
 public:
  Method(SSL_METHOD *method);

  static const MethodFuncPtr TLSv1;

 private:
  SSL_METHOD *m_method;
};
extern "C" {
  typedef SSL_METHOD*(*MethodFuncPtr)(void);
  typedef const SSL_METHOD*(*ConstMethodFuncPtr)(void);
}

class Method
{
 public:
  Method(SSL_METHOD *method);

  static ConstMethodFuncPtr TLSv1;

 private:
  SSL_METHOD *m_method;
};

我为const SSL_方法*返回类型添加了一个typedef。编译器很高兴

C++标题:

#include <ssl.h>

extern "C" {
  typedef SSL_METHOD*(*MethodFuncPtr)(void);
}

class Method
{
 public:
  Method(SSL_METHOD *method);

  static const MethodFuncPtr TLSv1;

 private:
  SSL_METHOD *m_method;
};
extern "C" {
  typedef SSL_METHOD*(*MethodFuncPtr)(void);
  typedef const SSL_METHOD*(*ConstMethodFuncPtr)(void);
}

class Method
{
 public:
  Method(SSL_METHOD *method);

  static ConstMethodFuncPtr TLSv1;

 private:
  SSL_METHOD *m_method;
};
C++源代码:

Method::Method(SSL_METHOD* method)
  : m_method(method)
{ }

const MethodFuncPtr Method::TLSv1 = TLSv1_method;
Method::Method(SSL_METHOD* method)
  : m_method(method)
{ }

ConstMethodFuncPtr Method::TLSv1 = TLSv1_method;

这个方法不应该是ssl_METHOD*方法吗;be MethodSSL_METHOD;?看起来您有一个指向函数指针的指针,我怀疑您不需要。您有一个返回常量SSL_METHOD*的函数,以及一个期望函数返回非常量SSL_METHOD*的变量。这两者是不相容的。修正其中一个,使之与另一个相匹配。这不是真正的C问题。