CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    May 2002
    Posts
    7

    Accessor function for CPoint data member

    Hello,

    This is probably real simple, but I can't seem to figure it out.

    I have a CPoint object that is a data member of another class.
    and all of the data members are protected.

    I want to return a CPoint object using a getfunction() method to get the values of x and y in which to use it in another class definition. All of my other getfunction() methods returns a primitive data type.

    Is this a reasonable approach? A code example would be great!

    for some reason, I haven't seen an accessor function that returns an object.

    I appreciate any help.

  2. #2
    Join Date
    May 2002
    Location
    Poland
    Posts
    48
    Since CPoint is a really simple object, I don't see any reasons not to return it from a function, as well as pass it as a argument etc. Returning a reference allows anyone to modify this object and that's not the idea of having a protected member.

    Code:
    class CSomeClass
    {
    
    public:
    CPoint GetPoint() { return m_point; }
    
    protected:
    CPoint m_point;
    };
    regards,
    MiMec

  3. #3
    Join Date
    Jun 2000
    Posts
    305
    Code:
    class yourClass {
       public:
          //...
          getX();
          getY();
       protected:
          CPoint myPoint;
    }
    
    // In yout cpp file
    
    int yourClass::getX()
    {
       return myPoint.x;
    }
    int yourClass::getY()
    {
       return myPoint.y;
    }
    I don't know if this is what you need...but

  4. #4
    Hi,
    this link may help you: http://www.********.net/
    It shows the advance gdi and other features you like. The client may interest you.

    Regards
    jack

  5. #5
    Join Date
    May 2002
    Posts
    7

    Accessor function - CPoint

    Thanks to all of the replies.

    It wasn't as "deep" as I thought it was.

    I appreciate the help.

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