I create a table in c++. I have a class with the table skills. I would like to get memory for the square table with function, but I don't know how I should code the constructor and the function for memory allocation.
I get the size from keyboard and I'd like to give this return statement for an other function that allocates the memory. Table must be an 2-dimensions array[][] or matrix.
#include <iostream>
using namespace std;
class Table {
unsigned int size;
public:
unsigned int GetTableSize();
unsigned int *GetMemory(unsigned int);
};
unsigned int Table::GetTableSize() {
cout << "Give size: " << endl;
cin >> size;
return size;
}
unsigned int *Table::GetMemory(unsigned int s){
s = size;
return new unsigned int[s * s];
}
int main()
{
Table tab;
tab.GetTableSize();
tab.GetMemory();
return 0;
}
*GetMemory function must return with the memory size of the table. I have problem with tab.GetMemory. I tried tab.*GetMemory as well.
tab*GetMemory: QT creator says: GetMemory is not declared. tab.GetMemory: Qt creator says: not matching function for call 'Table::Getmemory'.