797成员初始化列表中的列表初始化或非实现的非静态数据成员初始化

797成员初始化列表中的列表初始化或非实现的非静态数据成员初始化

本文介绍了c2797成员初始化列表中的列表初始化或非实现的非静态数据成员初始化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



c2797:成员初始化列表中的列表初始化或非静态方法数据成员初始化程序未实现



这是一段代码,它会抛出上述编译器错误。



==== sample.h ====

 枚举类Process 
{


TUNNEL_IP_VERSION,// Tunnel :: IPVersion :: Type
PADDING_BYTE,
IP_ADDRESS_FIT_ACTUAL_SIZE,
IP_ADDRESS_FIT_IPv6_SIZE,
PORT_NUMBER,
};

使用ProcessingOrder = std :: vector< Process> ;;

const ProcessOrder m_ProcessingOrder =
{


Process :: TUNNEL_IP_VERSION,
Process :: PADDING_BYTE,
Process :: IP_ADDRESS_FIT_IPv6_SIZE,
Process :: PORT_NUMBER
};



Eventhough VS2013支持c ++ 11功能 - 初始化列表,为什么会通过上述错误!如何下车这种情况?



感谢您的回答。这工作伟大。
我也有类似的情况下面的语句以及。

  m_Attribute {SSL_CTX_new(g_SSLChoice [version] .m_pfSSLMethod()),0,0} 
{

其中,
m_Attribute

  struct {
SSL_CTX * const m_pContext;
Socket * m_pSocket;
X509 * m_pCertificate;
} m_Attribute;

SSL_CTX_new是ssl.haveework中的标准定义,
g_SSLChoice是,

  g_SSLChoice [CloudSSL :: TLSv1_2 + 1] = 
{
/ * [SSLv23] = * / {& SSLv3_client_method,0},
/ * [SSLv3] = * / {& SSLv23_client_method,SSL_OP_NO_SSLv2},
/ * [TLSv1] = * / {& TLSv1_client_method,SSL_OP_NO_SSLv3} b $ b / * [TLSv1_1] = * / {& TLSv1_1_client_method,SSL_OP_NO_TLSv1},
/ * [TLSv1_2] = * / {& TLSv1_2_client_method,SSL_OP_NO_TLSv1_1}
};

其中,

 class CloudSSL:public Util :: Thread 
{

public:enum版本
{
// SSLv2,//不支持
SSLv23,
SSLv3,
TLSv1,
TLSv1_1,
TLSv1_2
};

最后m_pfSSLMethod是,
const SSL_METHOD *(* m_pfSSLMethod)();

解决方案

Visual Studio没有实现此功能然而。您可以在找到解决方法。



您可以使用

  const ProcessingOrder m_ProcessingOrder = ProcessingOrder 
{
Process: :TUNNEL_IP_VERSION,
Process :: PADDING_BYTE,
Process :: IP_ADDRESS_FIT_IPv6_SIZE,
Process :: PORT_NUMBER
};

对于第二种情况。

  struct Attribute_t {
SSL_CTX * const m_pContext;
Socket * m_pSocket;
X509 * m_pCertificate;
} m_Attribute;

然后只是

  m_Attribute = Attribute_t {SSL_CTX_new(g_SSLChoice [version] .m_pfSSLMethod()),
0,0}


I m getting the following error in visual studio 2013 when i try to compile my project.

c2797:List initialization inside member initializer list or non static data member initializer not implemented.

Here is the piece of code for which it is throwing the above compiler error.

====sample.h====

enum class Process
{


  TUNNEL_IP_VERSION,  // Tunnel::IPVersion::Type
  PADDING_BYTE,
  IP_ADDRESS_FIT_ACTUAL_SIZE,
  IP_ADDRESS_FIT_IPv6_SIZE,
  PORT_NUMBER,
};

using ProcessingOrder = std::vector<Process>;

const ProcessingOrder m_ProcessingOrder =
{


  Process::TUNNEL_IP_VERSION,
  Process::PADDING_BYTE,
  Process::IP_ADDRESS_FIT_IPv6_SIZE,
  Process::PORT_NUMBER
};

Eventhough VS2013 supports c++11 feature - intialize list , why it is throughing the above error !? How to get off with this situation? What do i need to change in the code to fix this?

Thanks for your answer. That works great.I have a similar situation for the below statement as well.

m_Attribute{SSL_CTX_new(g_SSLChoice[version].m_pfSSLMethod()), 0, 0}
  {

where,m_Attribute is,

struct{
         SSL_CTX* const m_pContext;
         Socket* m_pSocket;
         X509* m_pCertificate;
         }m_Attribute;

SSL_CTX_new, is a standard definition in ssl.have
g_SSLChoice is,

g_SSLChoice[CloudSSL::TLSv1_2 + 1] =
  {
    /* [SSLv23] = */ {&SSLv3_client_method, 0},
    /* [SSLv3] = */ {&SSLv23_client_method, SSL_OP_NO_SSLv2},
    /* [TLSv1] = */ {&TLSv1_client_method, SSL_OP_NO_SSLv3},
    /* [TLSv1_1] = */ {&TLSv1_1_client_method, SSL_OP_NO_TLSv1},
    /* [TLSv1_2] = */ {&TLSv1_2_client_method, SSL_OP_NO_TLSv1_1}
  };

in which,

class CloudSSL : public Util::Thread
  {

public: enum Version
        {
          // SSLv2,  // Not supported
          SSLv23,
          SSLv3,
          TLSv1,
          TLSv1_1,
          TLSv1_2
        };

And finally m_pfSSLMethod is,const SSL_METHOD* (*m_pfSSLMethod)();

解决方案

Visual Studio did not implement this feature yet. An workaround can be found here

You can just use

const ProcessingOrder m_ProcessingOrder = ProcessingOrder
{
  Process::TUNNEL_IP_VERSION,
  Process::PADDING_BYTE,
  Process::IP_ADDRESS_FIT_IPv6_SIZE,
  Process::PORT_NUMBER
};

For your second case.

struct Attribute_t{
         SSL_CTX* const m_pContext;
         Socket* m_pSocket;
         X509* m_pCertificate;
         }m_Attribute;

then just

m_Attribute = Attribute_t{SSL_CTX_new(g_SSLChoice[version].m_pfSSLMethod()),
0, 0}

这篇关于c2797成员初始化列表中的列表初始化或非实现的非静态数据成员初始化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 14:03