473,385 Members | 1,312 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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.hpp" //classes...
#include "classe2.hpp"

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 1680
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.hpp" //classes...
#include "classe2.hpp"

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*****@rochester.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_CLASS1DEF_

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

Jorge L.
Jul 22 '05 #4

"Jorge Rivera" <jo*****@rochester.rr.com> wrote in message
news:44******************@twister.nyroc.rr.com...
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*****@rochester.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.learn.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
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...
1
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....
31
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();...
2
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...
2
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...
13
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...
34
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...
2
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...
3
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.