Click to See Complete Forum and Search --> : Class Design problem
micromysore
May 30th, 2003, 09:30 AM
hi ..
here are my classes ..
class WellData ;
class SpotData ;
class Cell
{
protected:
int x1,y1;
int x2,y2;
WellData **well;
public:
Cell();
virtual ~Cell();
};
class WellData : public Cell
{
protected:
int x1,y1;
int x2,y2;
SpotData **spot;
public:
WellData();
~WellData();
};
class SpotData : public WellData
{
int x1,y1;
int x2,y2;
public:
SpotData();
};
I have in the usage ..
Cell assay;
I cannot access .. Spotdata private members from Cell .. but the other way is TRUE .. like .. I can access .. derived class members ..
How can i make 2 way access work ..
like.. from assay .. sud be able to acces .. welldata and spotdata ..
thank you
regards,
micromysore
micromysore
May 30th, 2003, 09:38 AM
Since I have a SpotData 2D pointer !! .. it gets initialized to soem some junk ..
letz assume ..
spot=new SpotData*[spotrow];
for(int row=0;row<spotrow;row++)
spot[row]=new SpotData[spotcol];
return TRUE;
were spotrow and spotcol are member variable ..
now while for deallocating the above memory .. if i donno what spotrow and spotcol are[they are modified ], how to find the the 2D length ..
if we do memalloc without bothering to dealloc the previously allocated memory .. what happens ??
regards,
micromysore
fleck
May 30th, 2003, 11:29 AM
hey, sorry when i' m wrong, but you' re deriving a class from another one that' s including a pointer to the derived one, are you shure to do so, or do i' ve to learn more about oo
mholm
May 30th, 2003, 11:47 AM
You are not clear enough! Explain more please!
Graham
May 30th, 2003, 12:26 PM
You've got a serious design problem here, but first let me make the point: of course you can't access the private members - they're private. That's what private means: only the class itself and any friends are allowed access. And before you start adding friend statements all over the place, let me say that that would be a bad idea.
Now, it looks to me as if your notion of using public derivation is wrong. From what little you've posted, it seems as if simple containment is all that's needed. I find it hard to believe that a WellData IS-A Cell and that a SpotData IS-A WellData. Why have you declared pointer-to-pointer members? If you want a 2-D array, there are better ways.
Your best bet now is to explain what you are trying to achieve, not just post code that has no rational reason to exist.
micromysore
May 30th, 2003, 03:00 PM
hi !!
All i am trying to do is draw grids in VC++ for which i the user gives leftTOP and BottomRIGHT points !! Also now of wells in each rows and each cols .. and nos of spots in each rows and columns ..
so the data is .. like this !! This is not the actual code .. just wrote to make the problem more clear !!
Class Welldata;
Class Spotdata;
Class Cell
{
public:
int x1,y1; //LeftTop
int x2,y2; //BottomRight
int wellrow,wellcol,spotrow,spotcol;
Welldata **well;
Allocdata();
};
Cell::Cell()
{
//all members initialised to ZERO
}
Cell::Allocdata()
{
//Assume mem allocated
well=new Welldata[wellrow][wellcol]
//For each row call spot mem allocation
for(i=0;i<wellrow;i++)
for(j=0;j<wellcol;j++)
well[i][j].Allocdata();
}
Class Welldata:public Cell
{
public:
int x1,y1; //LeftTop
int x2,y2; //BottomRight
Spotdata **spot;
Allocdata();
};
Welldata::Allocdata()
{
//Assume mem allocated
spot=new Welldata[spotrow][spotcol]
}
Class Spotdata:public Welldata
{
public:
int x1,y1; //LeftTop
int x2,y2; //BottomRight
};
regards,
micromysore
Paul McKenzie
May 30th, 2003, 03:54 PM
Is a SpotData a WellData? If not, why are you publicly deriving SpotData from WellData?
I highly suggest you rethink this whole thing. It looks like you are just throwing around classes without proper knowledge of what public inheritance means, and hoping something compiles.
Regards,
Paul McKenzie
micromysore
May 30th, 2003, 03:58 PM
hi,
the sequence is liek this ..
Many spots form a well
many wells form a CELL
There is always a single CELL ..
CELL -> WELLs->Spots ..
if have the present setup ..
assuming ..
i have
Cell assay;
I can access the spots as
assay.well[row][col].spot[row1][col1].x1 .. something like thing .. It makes things easier for me ..
regards,
micromysore
Graham
May 30th, 2003, 04:32 PM
Originally posted by micromysore
hi,
the sequence is liek this ..
Many spots form a well
many wells form a CELL
As I said: you want containment; not, and I repeat NOT, inheritance.
A Cell contains wells and a Well contains Spots.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.