|
-
May 23rd, 2002, 10:45 AM
#1
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.
-
May 23rd, 2002, 10:49 AM
#2
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
-
May 23rd, 2002, 10:52 AM
#3
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
-
May 23rd, 2002, 10:57 AM
#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
-
May 23rd, 2002, 12:54 PM
#5
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|