By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,171 Members | 963 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,171 IT Pros & Developers. It's quick & easy.

enum variable

P: 1
Hi, all,

I define an enum in class PeriodicalItem; there is also a enum type varaible in this class:
//PeriodicalItem .h
Expand|Select|Wrap|Line Numbers
  1. class PeriodicalItem {
  2.  
  3. public:
  4.     enum Regularity { Daily, Weekly, Fortnightly, Monthly, BiMonthly, Quarterly, TriAnnual, BiAnnual, Annual };
  5.  
  6. public:    
  7.     PeriodicalItem(const string &title, const string &call_number, const Regularity &published);
  8. private:
  9.     Regularity m_Published;
  10. };
The problem is, how can I create a instance of this class, with value Weekly of this enum in main function?
I mean, in Java, it could be implemented by:
Expand|Select|Wrap|Line Numbers
  1. PeriodicalItem items = new PeriodicalItem("C/C++ Users Journal", "005.133 Cus", PeriodicalItem.Regularity.Monthly);
what shall I do in C++?

PeriodicalItem::Regularity.Monthly?


Thanks.
Mar 13 '07 #1
Share this Question
Share on Google+
2 Replies


Expert 100+
P: 1,510
you can access using the :: operator, e.g.
Expand|Select|Wrap|Line Numbers
  1.     cout << PeriodicalItem::Weekly << endl;
  2.  
Mar 13 '07 #2

Ganon11
Expert 2.5K+
P: 3,652
You could also define the enum type outside of the class and be able to use it normally.
Mar 13 '07 #3

Post your reply

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