简体   繁体   中英

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

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}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM