473,770 Members | 2,160 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

enum visibility problem

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.
}
Oct 1 '05 #1
2 5495
Sandy wrote:
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.
}


Oct 1 '05 #2
Sandy wrote:
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
Oct 1 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
5482
by: lawrence | last post by:
Can anyone tell me why this code works in Netscape 7.1 but not in IE??? <SCRIPT type='text/javascript'> function makeVisible(nameOfDiv) { document.getElementById(nameOfDiv).style.visibility='visible'; document.getElementById(nameOfDiv).style.height='auto'; if (nameOfDiv != 'weblogs')
21
4603
by: Andreas Huber | last post by:
Hi there Spending half an hour searching through the archive I haven't found a rationale for the following behavior. using System; // note the missing Flags attribute enum Color {
1
4696
by: Bill Cohagan | last post by:
I've got an abstract class (say foo) and I'd like to define an Enum (say bar) within that class so that I can then refer to foo.bar.<one of the enum labels> from within other parts of the program. The enum is *public* in other words. What I find is that while the compiler allows the enum declaration within the abstract class, it turns out that the enum type isn't visible from outside the class. It is visible from within descendant...
18
11368
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
10
23611
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.
11
2634
by: -D- | last post by:
How can I turn the visibility of the xml control on or off? <%@ Control Language="c#" AutoEventWireup="false" Codebehind="TopNavBar.ascx.cs" Inherits="compass.user_controls.TopNavBar" TargetSchema="http://schemas.microsoft.com/intellisense/ie5"%> <table cellSpacing="0" cellPadding="0" border="0"> <colgroup span="1" align="left" width="50%"> </colgroup> <colgroup span="1" align="right" width="50%"> </colgroup>
13
18152
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 };
3
7649
by: dev_15 | last post by:
Hi, I have this problem that i want to use an enum as a return value of a private method in my class, but compiler won't let me use as such Code here: class CDisplayUtil { public: enum DISPLAYMODE {
6
1423
by: =?Utf-8?B?R2Vvcmdl?= | last post by:
Hello everyone, Suppose I have two enums which has an item with the same names -- but different values, enum foo { NAME = 100;
0
10260
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9906
tracyyun
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...
0
8933
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7456
isladogs
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...
0
5354
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...
0
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4007
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
2
3609
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2850
bsmnconsultancy
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.