new T[...] returns a T* pointer, where T in your case is PCB*, thus you are asking new[] to return a PCB** pointer, which cannot be assigned to a PCB*[] 1 fixed array, hence the error.
(1 you are not specifying the size of the array, which is invalid syntax)
You need to change your table declaration to match what new[] actually returns, eg:
class PCBTable {
private:
PCB** table;
int table_size;
public:
PCBTable(int size);
~PCBTable();
};
PCBTable::PCBTable(int size) : table_size(size) {
table = new PCB*[size];
for (int i = 0; i < size; ++i) {
table[i] = new PCB;
}
}
PCBTable::~PCBTable() {
for (int i = 0; i < table_size; ++i) {
delete table[i];
}
delete[] table;
}
Alternatively, if you just need an array of objects, rather than an array of pointers to objects:
class PCBTable {
private:
PCB* table;
int table_size;
public:
PCBTable(int size);
~PCBTable();
};
PCBTable::PCBTable(int size) {
table_size = size;
table = new PCB[size];
}
PCBTable::~PCBTable() {
delete[] table;
}
That being said, you really should be using std::vector instead of new[]/delete[] manually. And if you are using C++11 or later, use std::unique_ptr or std::shared_ptr instead of raw pointers, eg:
#include <vector>
#include <memory>
class PCBTable {
private:
std::vector<std::unique_ptr<PCB>> table;
public:
PCBTable(int size);
};
PCBTable::PCBTable(int size) : table(size) {
for (auto &elem : table) {
elem = std::make_unique<PCB>();
}
}
Or:
#include <vector>
#include <memory>
class PCBTable {
private:
std::vector<PCB> table;
public:
PCBTable(int size);
};
PCBTable::PCBTable(int size) : table(size) {
}
new[]stuff and usestd::vector. If you're slinging bare pointers around, you may want to wrap those as well.PCB* table[];is not valid.