0

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'.

Jaden
  • 30
  • 9
  • What else falls into the group of 'data variable'? Is it defined somewhere? Or do I just remember what error statements mean when parts of those are undefined? – Jaden Nov 03 '14 at 18:05

2 Answers2

2

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.

nvoigt
  • 75,013
  • 26
  • 93
  • 142
  • Seems kinda silly now that I needed to know what they meant by data variable instead of focusing on the whole redefinition part. – Jaden Nov 03 '14 at 16:46
  • Well, the "you probably meant" is guesswork. But your compiler does not take guesses what you meant, it just tells you what is wrong :) – nvoigt Nov 03 '14 at 16:48
  • This didn't seem directed at my question, but it did solve the problem. The other problem, compiler error messages, is a mess in itself. – Jaden Sep 28 '15 at 18:17
0

'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.

Jaden
  • 30
  • 9