•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 456,577 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,629 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 2134 | Replies: 2
![]() |
•
•
Join Date: Aug 2004
Posts: 13
Reputation:
Rep Power: 5
Solved Threads: 0
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
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/~hawblit...-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:
Ed
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/~hawblit...-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
![]() |
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- Removing an item from head of linked list (C)
- Purpose of Pointers? (C++)
- Help needed :( (C++)
- Array of pointers to objects (C++)
- Pointers in C (C)
- how to place a specific info from input file (C)
Other Threads in the C++ Forum
- Previous Thread: How to access a Public Pointer value of a class directly?
- Next Thread: C++ Macros - help please


Linear Mode