hi all
when I am running the below program
#include<iostre am>
enum one
{
a=1000,b=2000,c ,d,z};
int main()
{
one* a1;one* a2;one* a3;
a1=&a;a2=&b;a3= &c;
int fun1(one*,one*, one*);
int x;
cout<<"the starting values are"<<a<<"\t"<< b<<"\t"<<c<<"\t "<<d<<"\t"< <z;
x=fun1(a1,a2,a3 );
cout<<"the sum of the values are\t"<<d;
return 0;}
int fun1(one *a,one *b,one *c)
{
return (*b-*a);
}
I am getting the following errors
non-lvalue in unary `&'
enumptr.cpp:9: non-lvalue in unary `&'
Actually I want to pass the address of the variables a,b,c using the pointers
a1,a2,a3 using the function fun1
I am assigning the adress of a,b,c to a1,a2,a3 using "&" operator
Is it the wright way of assigning the address in C++
please help me
21 7018 arne 315
Recognized Expert Contributor
Actually I want to pass the address of the variables a,b,c using the pointers
a1,a2,a3 using the function fun1
The problem is that a,b, ... are no variables, but enumeration constants. Try something like -
int a = 1000;
-
int *a1;
-
a1 = &a;
-
This should work.
The problem is that a,b, ... are no variables, but enumeration constants. Try something like -
int a = 1000;
-
int *a1;
-
a1 = &a;
-
This should work.
Thanks for the fast reply,
Its working with int format
what about the enum, is it that enum constats cant be stored in pointers
regards
srikar
arne 315
Recognized Expert Contributor
Thanks for the fast reply,
Its working with int format
what about the enum, is it that enum constats cant be stored in pointers
regards
srikar
Enumerations simply asssociate names with integer values. Therfore, names in enumerations are very similar to constants defined using #define. The only two advantages of enums I am aware of are that
- the assignment of the values happens automatically, and
- the names may persist through to the debugger (which may help with debugging).
You can, however, define enumeration variables and access the address of them, but at the moment I have no idea what that may be good for ...
Enumerations simply asssociate names with integer values. Therfore, names in enumerations are very similar to constants defined using #define. The only two advantages of enums I am aware of are that
- the assignment of the values happens automatically, and
- the names may persist through to the debugger (which may help with debugging).
You can, however, define enumeration variables and access the address of them, but at the moment I have no idea what that may be good for ...
Thanks for the information given
So enum values cannot be assigned to pointer variables.
Can we make casting for enum variables to data types other than int.
regards
srikar
arne 315
Recognized Expert Contributor
Thanks for the information given
So enum values cannot be assigned to pointer variables.
Can we make casting for enum variables to data types other than int.
regards
srikar
Enumerators (enumeration constants) are no variables, they're constants. They can be used whenever you use an integral type.
How would such a "cast to data types other than int" look like?
Hi thanks once again.
Can we type cast a enum value with (void*) inorder to get the adress on
a 32 bit machine. Is it possible.
regards
srikar
hi all,
how to get the address of an enum constant.
Can we make type casting of enum constant to (void*) on 32 bit machine where
both enum and address are of same size.
please help me
arne 315
Recognized Expert Contributor
Hi thanks once again.
Can we type cast a enum value with (void*) inorder to get the adress on
a 32 bit machine. Is it possible.
regards
srikar
Sure, you can instantiate an enum (just as a struct or a union): -
#include <stdio.h>
-
-
enum Num { jan, feb, mar };
-
-
int main( void )
-
{
-
enum Num a;
-
-
printf( "%p\n", &a );
-
-
return 0;
-
}
-
But for what could you use that?
Banfa 9,065
Recognized Expert Moderator Expert
You can't, an enum defined value has no memory space, therefore it has no address.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Glenn Venzke |
last post by:
I'm writing a class with a method that will accept 1 of 3 items listed in an
enum. Is it possible to pass the item name without the enum name in your
calling statement?
EXAMPLE:
public enum EnumName
FirstValue = 1
SecondValue = 2
ThirdValue = 3
|
by: Ajax Chelsea |
last post by:
can not the "static const int" be replaced by "static enum" anywhere?
is it necessary that define special initialization syntax for "static const int"?
|
by: Steven T. Hatton |
last post by:
Any opinions or comments on the following? I don't say it below, but I came
out on the side of using enumerations over static constants.
/* I'm trying to figure out the pros and cons of using static const
* int class members as opposed to using enumerations to accomplish a
* similar goal. The use of static constants seems more explicit and
* obvious to me. Unless I assign values to the enumerators, the
* compiler will do it for me....
|
by: Bilgehan.Balban |
last post by:
Hi,
I have two different enum definitions with members of same name. The
compiler complains about duplicate definitions. Is this expected
behaviour?
Can't I have same-named fields in different enum definitions? I think
it should have been perfectly valid to do that. Its a stupid limitation
to have to define disjoint enum symbol definitions. This is like having
to have disjoint member names in structures.
|
by: Visual Systems AB \(Martin Arvidsson\) |
last post by:
Hi!
I have created an enum list like this:
enum myEnum : int
{
This = 2,
That,
NewVal = 10,
LastItm
| |
by: kar1107 |
last post by:
Hi all,
Can the compiler chose the type of an enum to be signed or unsigned
int? I thought it must be int; looks like it changes based on the
assigned values. Below if I don't initialize FOO_STORE to be, say -10,
I get a warning about unsigned comparison and I'm seeing an infinite
loop.
If I do initialize FOO_STORE = -10, I don't see any warnings. No
infinite loop.
|
by: toton |
last post by:
Hi,
I have some enum (enumeration ) defined in some namespace, not inside
class. How to use the enum constant's in some other namespace without
using the whole namespace.
To say in little detail, the enum is declared as,
namespace test{
enum MyEnum{
VALUE1,VALUE2
};
|
by: Steven Nagy |
last post by:
So I was needing some extra power from my enums and implemented the
typesafe enum pattern.
And it got me to thinking... why should I EVER use standard enums?
There's now a nice little code snippet that I wrote today that gives me
an instant implementation of the pattern. I could easily just always
use such an implementation instead of a standard enum, so I wanted to
know what you experts all thought.
Is there a case for standard enums?
|
by: Gangreen |
last post by:
I have the following enum.
**
* An enum to represent types of mechanics.
*
* @author
* @version 1.0
*/
public enum Mechanics {
ISOLATION(0),
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |