I am working on a program that has a grid of object pointers that point to either a Null value or a derived child. I want to be able to set values on this grid to the address of their derived child such that I can "place" a child on the grid and access the child through their location in memory.
Heres what the interface looks like for the grid.
class Grid{
public:
virtual int get(g_type) const;
public:
parent* operator() (int,int);
Grid() : _amtCol(10),_amtRow(10)
{construct();}
~Grid() {deconstruct();}
private:
int _amtCol;
int _amtRow;
parent* **_grid;
private:
parent ***meddle(access);
void meddle(access, parent***);
virtual void construct();
virtual void deconstruct();
};
Heres what the () overload looks like.
parent* Grid::operator() (int i,int j){
if(i < get(r_QTY) && j < get(c_QTY)){
return this->meddle(key)[i+1][j+1];
}else{return NULL;}
}
What I want to be able to do is call this within the rest of my program as:
Grid b;
Child c;
Child c2;
b(1,1) = &c;
b(1,4) = &c2;
b(1,1)->foo(); //calls the first Childs foo()
b(1,4)->foo(); //calls the second Childs foo()
The rest of my classes are created and work as far as inheritance and structure go.
Is there a way that I could chain the overloads or something such that this works?
I thought that perhaps I needed to iron out my assignment overloads in the parents and child class's but they seem to work great.
/////////////////////////////////////////////////////
An aside, I do have this implemented:
void Grid::operator() (int i,int j,parent &cpy){
if(i < get(r_QTY) && j < get(c_QTY)){
this->meddle(key)[i+1][j+1] = &cpy;
}
}
That does allows for this functionality.
There is my dissertation! Thanks!
////////////A quick addition: So perhaps I don't necessarily need to know if this is morally and ethically just. I have a way to implement the functionality that works. I guess I do understand that using something that already exists in a library is to be preferred over my own creations but the fact that it is do-able if you use a std::vector for example means that it is possible. I am wondering how this is made possible and where it exists in the language's syntax.