CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    May 2003
    Location
    Logan,Utah,USA
    Posts
    107

    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

  2. #2
    Join Date
    May 2003
    Location
    Logan,Utah,USA
    Posts
    107

    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

  3. #3
    Join Date
    Aug 2002
    Location
    germany
    Posts
    112
    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

  4. #4
    Join Date
    Mar 2003
    Posts
    36
    You are not clear enough! Explain more please!

  5. #5
    Join Date
    Apr 1999
    Location
    Altrincham, England
    Posts
    4,470
    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


  6. #6
    Join Date
    May 2003
    Location
    Logan,Utah,USA
    Posts
    107

    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 Welldataublic Cell
    {
    public:
    int x1,y1; //LeftTop
    int x2,y2; //BottomRight
    Spotdata **spot;
    Allocdata();
    };
    Welldata::Allocdata()
    {
    //Assume mem allocated
    spot=new Welldata[spotrow][spotcol]
    }

    Class Spotdataublic Welldata
    {
    public:
    int x1,y1; //LeftTop
    int x2,y2; //BottomRight
    };



    regards,
    micromysore

  7. #7
    Join Date
    Apr 1999
    Posts
    27,449
    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

  8. #8
    Join Date
    May 2003
    Location
    Logan,Utah,USA
    Posts
    107

    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

  9. #9
    Join Date
    Apr 1999
    Location
    Altrincham, England
    Posts
    4,470

    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
  •  





Click Here to Expand Forum to Full Width

Featured