473,769 Members | 2,365 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

enum type and classes

I'm using metroworks codewarrior and can't solve a redeclariotin of type
problem

I have several classes and each of them need to have a custom type called
enum X
now what I was thinking is to put the type in a seperate file and simply
attach it as a librabry to my main as follows:

In main.cpp

#include "X.hpp" //file with the enum type
#include "classe1.hp p" //classes...
#include "classe2.hp p"

If I leave it like that my classes do not see the declaration of a type X

If I attach the file into each class then I have a redeclaration problem as
my main sees the declaration twice (+1 once from the main)

I have tried to declare the enum in the private part of each class and have
the private before public but even then my definitions of each method within
the class do nott see the type.

I have tried to play with the linking order of each file without succes with
various combinations but I think there must be a simple way to have an enum
type being visibles in all files without redeclaration problems ?
Jul 22 '05 #1
5 1707
Your post is fairly generic. Without code it is hard to understand your
problem...
I have several classes and each of them need to have a custom type called
enum X
Why do you need this?
now what I was thinking is to put the type in a seperate file and simply
attach it as a librabry to my main as follows:

In main.cpp

#include "X.hpp" //file with the enum type
#include "classe1.hp p" //classes...
#include "classe2.hp p"

If I leave it like that my classes do not see the declaration of a type X Of course not. Each class must individually include X.hpp.

If I attach the file into each class then I have a redeclaration problem as
my main sees the declaration twice (+1 once from the main)
I think you have already solved the problem.
Just have both classe1.hpp and classe2.hpp include X.hpp.

I have tried to declare the enum in the private part of each class and have
the private before public but even then my definitions of each method within
the class do nott see the type.
I have no idea what you are trying to say here...
I have tried to play with the linking order of each file without succes with
various combinations but I think there must be a simple way to have an enum
type being visibles in all files without redeclaration problems ?

This will not help.

JLR

Jul 22 '05 #2

"Jorge Rivera" <jo*****@roches ter.rr.com> wrote in message
news:UC******** ******@twister. nyroc.rr.com...
I have several classes and each of them need to have a custom type called enum X


Why do you need this?

I want to have an object in each class that is declared of that type

If I attach the file into each class then I have a redeclaration problem as my main sees the declaration twice (+1 once from the main)


I think you have already solved the problem.
Just have both classe1.hpp and classe2.hpp include X.hpp.


As I said, if I include the X.hpp in both classe1.hpp and classe2.hpp then
the main sees both declarations and complains that there is a type
redeclaration

here is some code that may help you understand

//X.hpp

enum X {X1=0, X2, X3};

//Class1.hpp

some code
#include "X.hpp"
some more code

//Classe1.cpp

Classe1 definitions...

//Classe2.hpp

some code
#include "X.hpp"
some more code

//Classe2.cpp

Classe2 Definitions....


//main.cpp

some code
Classe1.hpp
Classe2.hpp
some more code


In this case my compiler complains that the type X is redeclared

Jul 22 '05 #3
Kaila,

you need to use macros to avoid redefinitions
//X.hpp #ifndef _XENUMDEF_
#define _XENUMDEF_
enum X {X1=0, X2, X3};

#endif
//Class1.hpp
#ifndef _CLASS1DEF_
#define_CLASS1D EF_

....
#endif
Let me know if this fixes your problem...

Jorge L.
Jul 22 '05 #4

"Jorge Rivera" <jo*****@roches ter.rr.com> wrote in message
news:44******** **********@twis ter.nyroc.rr.co m...
Kaila,

you need to use macros to avoid redefinitions
> //X.hpp

#ifndef _XENUMDEF_
#define _XENUMDEF_


duh I forgot to put it for the X.hpp, it works fine now.

Thanks
Jul 22 '05 #5
On Mon, 24 May 2004 02:27:12 GMT, Jorge Rivera
<jo*****@roches ter.rr.com> wrote in comp.lang.c++:
Kaila,

you need to use macros to avoid redefinitions
> //X.hpp

#ifndef _XENUMDEF_
#define _XENUMDEF_


Using include guard macros is generally a good idea, but they should
be in the programmer's namespace and not in the namespace reserved for
the implementation. The symbols you have defined above are illegal.

All symbols beginning with an underscore followed by an upper case
letter, or all symbols containing two consecutive underscores anywhere
within them, are reserved for the implementation by the C++ standard
and are not to appear in user code.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.l earn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Jul 22 '05 #6

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

Similar topics

3
4197
by: Hans De Schrijver | last post by:
Im puzzled by a data validation behavior I don't understand, related to enums. Stripped down scenario: enum Type {One=1, Two=2, Three=3} Type var1 = (Type)40; These two lines of code don't cause a compile error. In VB, trying to assign a value to a variable of an enum type does cause a
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...
31
3616
by: Michael C | last post by:
If a class inherits from another class, say Form inherits from control, then I can assign the Form to a variable of type Control without needing an explicit conversion, eg Form1 f = new Form1(); Control c = f; An enum value inherits from int but it doesn't get implicitly converted: HorizontalAlignment h = HorizontalAlignment.Center;
2
3228
by: Filip Wtterwulghe | last post by:
Hello, I have have module where I have created a public enumtype that I want to reuse in different classes . As soon as I create a public property with this type . Vb warns me that the 'Friend' type can not be used as a public type . Option Strict is on , so it's possible that this problem only occurs in this case .
2
1872
by: Alex Feldman | last post by:
Which of the following is better? Defining an enum type inside a class as a nested type, or in the the namespace? An example of nested type enumerated type would be: public Class Product Public Enum Status psNormal psCharged End Enum
13
18151
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 };
34
11203
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?
2
1471
by: =?Utf-8?B?ZGlhdG9tQG5ld3Nncm91cC5ub3NwYW0=?= | last post by:
Hello, I would like to create an enum that can be used accross all the classes in my windows solution. How can I do this. TROUBLESHOOTING I created a new .cs file in my windows solution. I call it Enumerations.cs. In this file I have written the following... using System;
3
8006
by: Dean Mitchell | last post by:
Hi everyone, We have a c++ server application that we are writing a GUI client application for. To save our time and to avoid duplicating all the code and functionality that already exists in c++ classes I am building a managed c++ assembly around these classes so that a c# program can use them. The problem is that alot of these c++ classes use enums, I would like to make these visible to the c# application but I cannot find a way to...
0
9423
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,...
0
10210
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
10043
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9990
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,...
1
7406
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
6672
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();...
1
3956
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
3561
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2814
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.