Hi
I tried to use a pointer to point to address of an enumurated constant but this made a compile error.
so can can I know address of an enumurated constant and use it with a pointer?
down is a sample code:

#include<iostream.h>
main()
{


enum Date {mainX=1,mainY};


const int *pPointer;


pPointer=&mainX;


cout<<*pPointer;


return 0;
}

thanks

Hi the_one2003a,

What's the point of pointing to an enumerated constant? I think the key is that an enum is really a constant. An enum statement 'enum Date {mainX=1,mainY}' is almost like one is saying
#define mainX 1
#define mainY 2

An enum is realy just a type. C++ only supports pointers to variables and not pointers to types. If you are interested in pointers to types, the closest king I can think of is my research on using typesafe languages with security features. (http://www.cs.dartmouth.edu/~hawblitz/publish/hawblitzel-space2004.pdf, http://www.cs.dartmouth.edu/~hawblitz/)

Anyways... if you wanted just to get at the value of an enum (not point to it), you could do the following:

#include<iostream.h>
main()
{
  
  enum Date {mainX=1,mainY};
  
  Date *pPointer = new Date;
  
  *pPointer=mainX;
  
  cout<<*pPointer;
  
  // mainX=3; ERROR  See?  enum really is just a constant
  cout<<*pPointer;
  
  return 0;
}

Ed

Hi
Thanks Cosi for again your great Help
you are just like an angle in my c++ problems.
I wanted to know this to know does c++ support this type of Pointing
and your answer made my mind clean for this prob.

hope to be able to help you in one of your probs someday.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.