C++ variable declaration is treated like a function declaration

后端 未结 1 977
小蘑菇
小蘑菇 2021-01-25 05:13

The question is fairly theoretical, though it\'s interesting what makes MS VS2010 treat the following variable declaration (inside main) like a function declaration

相关标签:
1条回答
  • 2021-01-25 05:30

    Declare it without the ():

    maidsafe::dht::PrivateKeyPtr pk;
    

    Unfortunately, for primitive types that gives you an uninitialized value, but in C++11 you can value initialize with {}:

    maidsafe::dht::PrivateKeyPtr pk{};
    

    For a related parsing issue, see the c++ most vexing parse.

    0 讨论(0)
提交回复
热议问题