Unresolved external symbol C++

和自甴很熟 提交于 2019-11-30 09:23:39

问题


I ahve a problem with a code below:

ProgrammSettings.h

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

Settings.cpp

#include "ProgrammSettings.h"

static bool LoadSettings()
{
    ProgrammSettings::fd = 2; // here error Unresolved symbol!!
    return true;
}

What i'm doing wrong? Thanks!


回答1:


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;



回答2:


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

 int ProgrammSettings::fd;



回答3:


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.



来源:https://stackoverflow.com/questions/13660017/unresolved-external-symbol-c

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!