|
-
May 30th, 2003, 09:30 AM
#1
Class Design problem
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
-
May 30th, 2003, 09:38 AM
#2
Add to my woes
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
-
May 30th, 2003, 11:29 AM
#3
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
-
May 30th, 2003, 11:47 AM
#4
You are not clear enough! Explain more please!
-
May 30th, 2003, 12:26 PM
#5
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.
Correct is better than fast. Simple is better than complex. Clear is better than cute. Safe is better than insecure.
-- Sutter and Alexandrescu, C++ Coding Standards
Programs must be written for people to read, and only incidentally for machines to execute.
-- Harold Abelson and Gerald Jay Sussman
The cheapest, fastest and most reliable components of a computer system are those that aren't there.
-- Gordon Bell
-
May 30th, 2003, 03:00 PM
#6
clarifying grid
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 ublic 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 ublic Welldata
{
public:
int x1,y1; //LeftTop
int x2,y2; //BottomRight
};
regards,
micromysore
-
May 30th, 2003, 03:54 PM
#7
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
-
May 30th, 2003, 03:58 PM
#8
Cell->well
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
-
May 30th, 2003, 04:32 PM
#9
Re: Cell->well
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.
Correct is better than fast. Simple is better than complex. Clear is better than cute. Safe is better than insecure.
-- Sutter and Alexandrescu, C++ Coding Standards
Programs must be written for people to read, and only incidentally for machines to execute.
-- Harold Abelson and Gerald Jay Sussman
The cheapest, fastest and most reliable components of a computer system are those that aren't there.
-- Gordon Bell
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|