未解析的外部符号C ++ [英] Unresolved external symbol C++

查看:200
本文介绍了未解析的外部符号C ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到以下程式码的问题:

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!

推荐答案

与只需要声明的实例变量不同,类的static成员变量也必须

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

目前,您的代码只包含声明。将静态 fd 变量的定义添加到cpp文件以修复错误:

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;

这篇关于未解析的外部符号C ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆