Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PASSING ENUM TO A FUNCTION

Status
Not open for further replies.

villica

Programmer
Feb 25, 2000
332
CA
How do you pass an enum to another function. The enum is in the header file under the public section. Any ideas anyone. Thank YOu <p>Villica<br><a href=mailto:villica67@hotmail.com>villica67@hotmail.com</a><br><a href= > </a><br>
 
I am uncertain, how exactly you have it setup, but because I havent worked with much enum, but it might work similar to most other things like a struct or someting that cant just simply pass its values like a charater arary without using pointers.<br>
<br>
I might try somehting like passing by reference<br>
void something(enum &theenum) <br>
or might need to be like a struct, which is more of a class than an object<br>
(enum Enumname &objectname)<br>
this would pass by reference, it doesnt make a copy, so any changes you make if you decide to will affect the original copy, I would have to try this to be certain you can pass it, now if it's declared in a class <br>
something like (enum classname::enumname &object) might be required, which only works if the function knows that class.<br>
<br>
let me know what happens <p>Karl<br><a href=mailto:kb244@bellsouth.net>kb244@bellsouth.net</a><br><a href= </a><br>Experienced in , or have messed with : VC++, Borland C++ Builder, VB-Dos, VB1 thru VB6, Delphi 3 pro, Borland C++ 3(DOS), Borland C++ 4.5, HTML, ASP(somewhat), QBasic(hehe, yea it was 4.5 too, least i didnt start with COBOL)
 
In C++ the constants in an enum are local to a class and known only to member and friend functions of the class. So if a class declares an enum , functions outside the class can refer to the enumerated constants by explicitly qualifying the name using the scope resolution operator. .<br>
For eg, <br>
Class finite {<br>
enum state{ init, reset, end};<br>
...<br>
}<br>
Now you can use the notation finite::init to access this constant. <br>
So you can just pass this to any function which takes integer as the parameter.<br>
Does it answer your question ?<br>
Siddhartha Singh<br>
<A HREF="mailto:ssingh@aztecsoft.com">ssingh@aztecsoft.com</A><br>
<br>

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top