静态struct链接器错误 [英] Static struct linker error

查看:202
本文介绍了静态struct链接器错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在C ++中创建一个静态结构:

 
static struct brushes
{
static HBRUSH白色;
static HBRUSH yellow;
};

但它不工作,我得到:

 
错误4错误LNK2001:未解析的外部符号public:static struct HBRUSH__ * Brushes :: white

p>

这个想法是能够使用 Brushes :: white Brushes :: yellow 整个程序,而无需创建画笔的实例。

解决方案

您必须在.cxx文件中定义静态成员,例如:

  HBRUSH刷子::白色; 

原因是头文件没有定义,只声明它。 p>

I'm trying to create a static struct in C++:

static struct Brushes
{
  static HBRUSH white ;
  static HBRUSH yellow ;
} ;

But its not working, I'm getting:

Error 4 error LNK2001: unresolved external symbol "public: static struct HBRUSH__ * Brushes::white"

Why?

The idea is to be able to use Brushes::white, Brushes::yellow throughout the program, without having to create an instance of Brushes.

解决方案

You have to define the static members somewhere, usually in the .cxx file, e.g.:

HBRUSH Brushes::white;

The reason is that the header file doesn't make the definition, it only declares it.

这篇关于静态struct链接器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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