1

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)();

Shivaraj Bhat
  • 841
  • 2
  • 9
  • 20
  • 1
    So? Error says, that this feature is not implemented in your version of visual studio. About what is your question? – ForEveR Jan 22 '15 at 09:02
  • Eventhough VS2013 supports c++11 feature - intialize list , why it is throughing the above error !? How to get off with this ? – Shivaraj Bhat Jan 22 '15 at 09:05
  • 3
    This feature was implemented in the first versions of VS2013, but was removed since Update 3 because of bugs in its implementation. – Andy Prowl Jan 22 '15 at 09:08
  • 1
    Possible duplicate of [error C2797 : list initialization inside member initializer list](http://stackoverflow.com/questions/27741521/error-c2797-list-initialization-inside-member-initializer-list) – chappjc Oct 11 '16 at 20:03

1 Answers1

4

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}
sergiol
  • 4,122
  • 4
  • 47
  • 81
ForEveR
  • 55,233
  • 2
  • 119
  • 133
  • I have added one more similar situation in the question itself., Your help would be appreciated.! Thanks – Shivaraj Bhat Jan 22 '15 at 09:52
  • 1
    @ShivarajBhat if you want to also use list-initialization in class, your struct shouldn't be anonymous, name it, and use same tecnique as with ProcessingOrder. – ForEveR Jan 22 '15 at 09:57
  • Sir, I tried that as you said earlier, But it is one of the parameter in the whole statement, Tyring your solution for the second scenario resulting in an error- expected ( or { in "=" position. The whole statement goes something like this: CloudSSL::CloudSSL (Tunnel::Manager* const pTunnelManager, const Version version) : Util::Thread(pTunnelManager->getm_ThreadManager()), m_pTunnelManager(pTunnelManager), m_Attribute = Attribute_t{ SSL_CTX_new(g_SSLChoice[version].m_pfSSLMethod()), 0, 0 } { – Shivaraj Bhat Jan 22 '15 at 10:29
  • 1
    @ShivarajBhat it's not in class initializer, it's initializer in initializer list. I have no idea, what your problem is. – ForEveR Jan 22 '15 at 10:35