Need help with arrays.

A default constructor that sets up an initial array of 5 unsigned longs, sets capacity to 5 and used to 0. So, my question is how do I accomplish this. I attempted in the code below.
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>

class
{
        public:
                unsigned long int  a[5];
	private:
		unsigned long * data;
		std::size_t used;
		std::size_t capacity;
		
};

Only have been working with c++ for one week.
Last edited on
You need to give a name to your class anonymous class isn't a good practice.
and you need to dynamically allocate memory to your class in Ctor and pass parameter as capacity,used so it will be a parameterised Ctor
like this?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>

class Numbers
{
 	public:
                Numbers();
		void insert(int item);
		void resize();
		void display();
		Numbers(const Numbers & other);
		void operator = (const Numbers& other);
	private:
		unsigned long * data;
		std::size_t used;
		std::size_t capacity;
		
};

Numbers::Numbers(){
	used = 0; capacity = 5;
}
Your post in another thread is correct
Topic archived. No new replies allowed.