473,405 Members | 2,344 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,405 software developers and data experts.

Problem in assigning an enum variable of another class

I have a class which declares an enum in its header file and have a friend class like that :

Expand|Select|Wrap|Line Numbers
  1. class A
  2. {
  3. //constructors and other members
  4. private:
  5.     enum type {x, y };
  6.     type enumtype;
  7.     friend class B;
  8.  
  9. };
Then I want to assign the field enumtype in the Class B which stores some instance of A
Expand|Select|Wrap|Line Numbers
  1. A element;
  2. element.etype=x; // this line gives compiler error x is not defined.
Why is that? I am including the A.h at the begining of class A
Nov 19 '11 #1
1 1982
Banfa
9,065 Expert Mod 8TB
You have 2 problems there, the enum is declared in A so using x does not use the right namespace for it. When you declare something inside a class to access it from outside of the class you need to include the class name to locate it, thus A::x.

However if you correct your code to do this you will still get an error because you have declared the enum private so it is not accessible externally to the class.
Nov 21 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Stewart Midwinter | last post by:
I've got an app that creates an object in its main class (it also creates a GUI). My problem is that I need to pass this object, a list, to a dialog that is implemented as a second class. I want...
5
by: bartek d | last post by:
Hello, Regarding my previous question about a class which is used to store a variable type vector. I tried to be more elaborate on the code. I'd be grateful for your suggestions. Am I going in...
3
by: BCC | last post by:
I have a simple container class with an enum: class MyObject { typedef enum { etype1, etype2 } EType; }; In another class I have a vector:
6
by: adamrfrench | last post by:
Let it be mentioned that Javascript is not my forte, so the solution to this could very well be a simple one. I am working on an AJAX function where I can pass a URL and the target ID in, and...
2
by: babylon | last post by:
I have an enum public enum MyEnum : int { X, Y } I have to do int a = (int) MyEnum.X; can i overload the operator or other means to do something like
5
by: M O J O | last post by:
Hi, I want to expose a enum from another class, is that possible and how? Here's an example Public Class ClassMaster Public Enum Colors
3
by: drummond.ian | last post by:
Hello Everyone, This problem's been causing me a lot of trouble and I'm hoping somebody can help me out!! I have a dialog-based MFC application in visual studio 2003. I want to call a...
0
by: hoganlai2006 | last post by:
Recently I have come across with a problem with enum. I have defined an enum as follows: private void btnViewNumber_Click(object sender, EventArgs e) { if...
11
by: puzzlecracker | last post by:
Say we have the following class (adapted from the standard): enum {i=1}; class X{ char v; enum{i=2} // why this is illegal? int f(){ return sizeof(c); } // and this is legal? };
3
by: AliR \(VC++ MVP\) | last post by:
Hi Everyone, I have writing a class that represents a object on a screen. The object has normal things like X,Y, Width, Height, ZOrder, and it also has drawing attributes and flags. It has...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
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,...
0
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...
0
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,...
0
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...
0
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...

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.