I want to share enum between 2 classes C1 and C2:
class C1
{
public:
enum shut {AAA,BBB, CCC};
shut m_C1;
void set(shut &s) { m_C1=s;}
};
class C2 : public Cother
{
public:
enum shut {AAA,BBB, CCC};
shut m_C2;
};
void main()
{
C1 a;
C2 b;
a.set(AAA);
b.m_C2 = a.m_C1;
}
Is there a more elegant way than the one I have found, but for which I
do not measure the side effects :
class Cenum
{
public:
enum shut {AAA,BBB, CCC};
};
class C1 : public Cenum
{
public:
shut m_C1;
void set(shut &s) { m_C1=s;}
};
class C2 : public Cother, Cenum
{
public:
shut m_C2;
}; 4 3782
Pierre Couderc wrote: I want to share enum between 2 classes C1 and C2:
class C1 { public: enum shut {AAA,BBB, CCC}; shut m_C1; void set(shut &s) { m_C1=s;} };
class C2 : public Cother { public: enum shut {AAA,BBB, CCC}; shut m_C2; };
void main() { C1 a; C2 b; a.set(AAA); b.m_C2 = a.m_C1; }
Is there a more elegant way than the one I have found, but for which I do not measure the side effects :
Yes. You don't need to make an enum a class member. Just put it on namespace
scope, and both classes can easily use them.
Rolf Magnus wrote: Pierre Couderc wrote:
I want to share enum between 2 classes C1 and C2:
class C1 { public: enum shut {AAA,BBB, CCC}; shut m_C1; void set(shut &s) { m_C1=s;} };
class C2 : public Cother { public: enum shut {AAA,BBB, CCC}; shut m_C2; };
void main() { C1 a; C2 b; a.set(AAA); b.m_C2 = a.m_C1; }
Is there a more elegant way than the one I have found, but for which I do not measure the side effects :
Yes. You don't need to make an enum a class member. Just put it on namespace scope, and both classes can easily use them. ,
Thank you, sure I can put it at at a higher scope, but this may conflict
with other declaration at higer level, obliging me to declare :
enum shut { SHUT_OK, SHUT_ERROR, SHUT_AAA, SHUT_BBB...}
My idea is to keep programation simpler or shorter inside these (friend
or not) classes : OK, ERROR, AAA,BBB...
Pierre Couderc wrote: <snip> Thank you, sure I can put it at at a higher scope, but this may conflict with other declaration at higer level, obliging me to declare : enum shut { SHUT_OK, SHUT_ERROR, SHUT_AAA, SHUT_BBB...}
My idea is to keep programation simpler or shorter inside these (friend or not) classes : OK, ERROR, AAA,BBB...
Thats why namespaces are there, to avoid such conflicts. Put the class
and enum declarations within a namespace.
-Arijit
Pierre Couderc <pi****@couderc.ccNOSPAM> wrote in news:cos6kh$1i9u$1
@biggoron.nerim.net: I want to share enum between 2 classes C1 and C2:
One option:
namespace shut_t {
enum shut {AAA,BBB, CCC};
}
class C1 {
public:
typedef shut_t::shut shut;
void set(shut &s);
shut m_C1;
// ...
};
class C2 {
public:
typedef shut_t::shut shut;
shut m_C2;
// ...
};
int main() {
C1 a;
C2 b;
a.set(shut_t::AAA);
// or with: using namespace shut_t;
a.set(AAA);
b.m_C2 = a.m_C1;
}
Regards
Paavo
class C1 { public: enum shut {AAA,BBB, CCC}; shut m_C1; void set(shut &s) { m_C1=s;} };
class C2 : public Cother { public: enum shut {AAA,BBB, CCC}; shut m_C2; };
void main() { C1 a; C2 b; a.set(AAA); b.m_C2 = a.m_C1; }
Is there a more elegant way than the one I have found, but for which I do not measure the side effects :
class Cenum { public: enum shut {AAA,BBB, CCC}; };
class C1 : public Cenum { public: shut m_C1; void set(shut &s) { m_C1=s;} };
class C2 : public Cother, Cenum { public: shut m_C2; }; This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Kenneth |
last post by:
I want to define an enum for possible languages in my application. My
enum look like this:
Public Enum Languages
English = 0
Portuguese = 1
End Enum
How can i reuse this enum in the rest of...
|
by: Kaila |
last post by:
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...
|
by: Mark Turney |
last post by:
Problem:
I have a vector full of two different derived class objects (class B
and class C) that are derived from the same base class A. I want to
loop through vector and invoke a member function...
|
by: moondaddy |
last post by:
I have some pubic Enums I like to use throughout my application. Now I'm
parsing the application out into smaller DLLs or projects. How an I share a
common Enum across all the projects?
...
|
by: aloneplayer |
last post by:
Hi, All,
I wrote a function to share a folder to individual user account with
WMI.
When I call it :
ShareFolder("c:\\test", "Test", "Shared by Riven", 8,
Environment.MachineName,...
|
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...
|
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...
|
by: Cmtk Software |
last post by:
I'm trying to define an enum which will be used from unmanaged c++, C++/CLI
managed c++ and from C#.
I defined the following enum in a VS dll project set to be compiled with the
/clr switch:
...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
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...
|
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...
| |