M
MN
Hi All, I'm new to C++. why isn't possible to use private variable
like in the next code. When compiling I get these errors:
error: ‘data’ was not declared in this scope
error: no pre-increment operator for type
#include <iostream>
using namespace std;
const int QUEUE_SIZE = 100;
class queue
{
private:
int count; // Number of data in queue
int data[QUEUE_SIZE]; // Data at position "count" in queue
public:
queue();
~queue();
void put(const int item); // Insert an item in the queue
void show(void); // Get the next item in the queue
};
queue::queue()
{
count = 0;
};
queue::~queue(){};
void put(const int item)
{
data[count] = item; //<--- Here a problem
++count; //<--- Here a problem
};
void show(void)
{
cout << "count is" << count<< "\n";
}
like in the next code. When compiling I get these errors:
error: ‘data’ was not declared in this scope
error: no pre-increment operator for type
#include <iostream>
using namespace std;
const int QUEUE_SIZE = 100;
class queue
{
private:
int count; // Number of data in queue
int data[QUEUE_SIZE]; // Data at position "count" in queue
public:
queue();
~queue();
void put(const int item); // Insert an item in the queue
void show(void); // Get the next item in the queue
};
queue::queue()
{
count = 0;
};
queue::~queue(){};
void put(const int item)
{
data[count] = item; //<--- Here a problem
++count; //<--- Here a problem
};
void show(void)
{
cout << "count is" << count<< "\n";
}