Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am looking at a legacy VC++ ActiveX project and find these statements in a header file:

typedef enum CursorMode {Fixed, Floating, Snap};
typedef enum Crosshair  {XY, X, Y};


I got this warning message:
Warning	C4091	'typedef ': ignored on left of 'Crosshair' when no variable is declared	NTGraph	c:\demo_temp\ntgraph_src\ntgraphctl.h


what is the purpose or benefit to do this ? try to get some insights from gurus in this community...

Thanks a million!

What I have tried:

I removed these typedef keyword and compile the project, no more warnings...
Posted
Updated 3-Jan-21 20:08pm
v2

Enumeration declaration - cppreference.com[^]

A useful usage is to make comparisons or assignments easier to read. Like:
C++
if (myCursorMode == CursorMode.Fixed)
{
  //do whatever
}
or
C++
if (whatever condition)
{
  myCursorMode = CursorMode.Snap;
}

instead of:
C++
if (myCursorMode == 1)
{
  //do whatever
}
or
C++
if (whatever condition)
{
  myCursorMode = 3;
}


As you don't say anything about the warnings I suppose they were like:
"XXX being declared but never used"?

If not... only because now it compiles without warning doesn't necessarily mean that it will be correctly executed. It might be that you get a runtime exception.

Without more information... difficult to say what it was.
 
Share this answer
 
Comments
Southmountain 3-Jan-21 18:24pm    
here is the warning message:
Warning	C4091	'typedef ': ignored on left of 'Crosshair' when no variable is declared	NTGraph	c:\demo_temp\ntgraph_src\ntgraphctl.h
Nelek 4-Jan-21 13:58pm    
Read Solution 2 and 3, the warning is coming because the code is not in the correct order or the typdef is not needed.
CPallini 4-Jan-21 2:04am    
5.
Nelek 4-Jan-21 13:23pm    
Thanks Carlo
Well, it won't compile, but apart from that ...

If you correct it:
typedef enum {Fixed, Floating, Snap} CursorMode;

All it's doing is declaring an enum that (in both cases) has three possible values, and using typedef to give it a type name that can be used like char, or int.

typedef enum {Fixed, Floating, Snap} CursorMode;
...
CursorMode cm = Floating;
cout << cm;
 
Share this answer
 
Comments
Southmountain 3-Jan-21 18:27pm    
thank you for your insight!
OriginalGriff 4-Jan-21 3:25am    
You're welcome!
CPallini 4-Jan-21 2:02am    
5.
(In addition to other solutions...) Please note in C++ you don't need the typedef at all, in the enum declaration. Try, for instance
C++
#include <iostream>
using namespace std;

enum CursorMode {Fixed, Floating, Snap};

int main()
{
  cout << Floating << endl;
}
 
Share this answer
 
Comments
Southmountain 4-Jan-21 15:08pm    
got it. Thank you!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900