What does 'data variable' mean in MSVS2010 in this error? I thought I was declaring a symbol that is defined elsewhere in my code.
error C2365: 'g_surf' : redefinition; previous definition was 'data variable'
Obviously this could mean an int or 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 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'.
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.
'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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.