简体   繁体   English

“数据变量”是什么意思?

[英]What is meant by 'data variable'?

What does 'data variable' mean in MSVS2010 in this error? 在此错误中,“数据变量”在MSVS2010中意味着什么? I thought I was declaring a symbol that is defined elsewhere in my code. 我以为是在声明代码中定义的符号。

error C2365: 'g_surf' : redefinition; 错误C2365:“ g_surf”:重新定义; previous definition was 'data variable' 先前的定义是“数据变量”

Obviously this could mean an int or char. 显然,这可能意味着一个int或char。
I followed a working example. 我遵循了一个有效的例子。
I had to include a definition of the class before declaring the symbol. 在声明符号之前,我必须包括该类的定义。

#include classdef.h

I used the extern keyword to declare an object in stdafx.h. 我使用extern关键字在stdafx.h中声明了一个对象。

extern COriginal g_orig;//works
extern CClass g_surf;//how is this declaration resulting in a 'data variable'  type?

I instantiate a class in a code file (in global space). 我在代码文件中(在全局空间中)实例化一个类。 This is where the error occurs. 这是发生错误的地方。

COriginal g_orig(CONST_ARGUMENT);//works
CClass g_surf();//seen as redefinition.

I created a class from two other classes because I need attributes from both. 我从其他两个类创建了一个类,因为我需要两个属性都具有。

I can find other redefinition questions that do not offer insight to this one. 我可以找到其他无法重新定义此问题的重新定义问题。 I haven't found in MSVS2010 or on the web what is meant by 'data variable'. 我在MSVS2010或网络上都找不到“数据变量”的含义。

You probably meant to call a constructor with no parameters. 您可能打算调用不带参数的构造函数。

CClass g_surf;

For your compiler, this line 对于您的编译器,此行

CClass g_surf();

is the forward declaration of a method called g_surf taking no parameters and returning a CClass. 是名为g_surf的方法的前向声明,该方法不带任何参数并返回CClass。

'Data variable' does appear to include symbols declared with class types. “数据变量”似乎确实包含用类类型声明的符号。
So, I was trying to redefine the type of the symbol to something else. 因此,我试图将符号的类型重新定义为其他类型。
I was trying to use the same symbol to declare a function. 我试图使用相同的符号来声明一个函数。

The mistake I was making in my code was adding parenthesis on the symbol name when instantiating a class. 我在代码中犯的错误是在实例化类时在符号名称上添加括号。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM