enum visibility problem

S

Sandy

I have an enum like this

file1.cpp
enum e {e1, e2};
extern void fun();
void main()
{
fun();
}


file2.cpp
extern enum e;
void fun()
{
enum e ee= e1; // Compilation error "error C2065: 'e1' : undeclared
identifier"
// How do i access the enum here, if i dont define it in a header file.
}
 
R

Rolf Magnus

Sandy said:
I have an enum like this

file1.cpp
enum e {e1, e2};
extern void fun();
void main()

main() must return int.
{
fun();
}


file2.cpp
extern enum e;
void fun()
{
enum e ee= e1; // Compilation error "error C2065: 'e1' : undeclared
identifier"
// How do i access the enum here, if i dont define it in a header
file.

You can copy the definition to file2.cpp, but honstely, I think it's better
to move the definition to the header. This is just the same as other user
defined types. If they are only forward declared, you cannot do much with
them.
 
J

John Harrison

Sandy said:
I have an enum like this

file1.cpp
enum e {e1, e2};
extern void fun();
void main()
{
fun();
}


file2.cpp
extern enum e;
void fun()
{
enum e ee= e1; // Compilation error "error C2065: 'e1' : undeclared
identifier"
// How do i access the enum here, if i dont define it in a header file.
}

Err, you define it in the header file. Put it in the header file so you
can share the definition between different source files. That's what
header files are for.

john
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,151
Latest member
JaclynMarl
Top