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


Tip of the Day
Home » Tip Bank » C++
Language: C++
Expertise: All
Feb 9, 1998

How to define an object-internal constant?

When you need a constant integer member in an object, the easiest way to create one is by using a nameless enum, which can be used like any
  const int:
 
class vector {
	int v_size;
	enum {MAX = 1024}; //nameless enum 
	char *p;

	public:
	vector() {p = new char[MAX]; }
	vector( int size) {if (size <= MAX)
				 	p = new char[size] ;
		      	else 
					p = new char[MAX]; }
}
Danny Kalev
 
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