dcsimg
Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Tip of the Day
Language: C++
Expertise: Beginner
Oct 18, 1999

WEBINAR:

On-Demand

Building the Right Environment to Support AI, Machine Learning and Deep Learning


Declaring Data for an Object

Question:
I'm trying to declare some data for an object such that, when necessary, other functions can use the object not only to perform member functions but also serve as a 'data container'.

For example, I'm declaring a Date object that, among other things, contains an array of all the month ends. So in the class declaration I'd like to do this:


class Date {

public:
	Date();
	~Date(){};

	int monthEnds[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
};
And from then on be able to rely the Date object to say:

February = Date::monthEnds[2];
I am going insane trying to find a good referrence for declaring array data within a class.

Answer:
You cannot initialize data memebers inside the class body. You need to perform the initialization inside the constructor.

DevX Pro
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date