Unresolved external symbol C++

后端 未结 3 825
花落未央
花落未央 2020-12-21 10:39

I ahve a problem with a code below:

ProgrammSettings.h

#pragma once
static class ProgrammSettings
{
public:
    static int fd;
};


        
相关标签:
3条回答
  • 2020-12-21 11:03

    Static data members declarations in the class declaration are not definition of them You have forgot to add the definition to match your declaration of fd.
    You must explicitly define your class's static data members.

    0 讨论(0)
  • 2020-12-21 11:07

    You need to add the following line to the start of your cpp file

     int ProgrammSettings::fd;
    
    0 讨论(0)
  • 2020-12-21 11:11

    Unlike instance variables that require only a declaration, static member variabs of the class must also be defined.

    Currently, your code contains only a declaration. Add a definition of your static fd variable to a cpp file to fix the error:

    int ProgrammSettings::fd;
    
    0 讨论(0)
提交回复
热议问题