Jump to content
Sign in to follow this  
mon678

Using Class,constructor,destructor And Accessor

Recommended Posts

nk minta tolong terangkan mcm mane nk gune accesor untuk access data private dlm class tue conth:-

Class X{
private:
int w;
int u;
public:
print()const;
};

mcm nk print out data private tue dlm function print()const tue?

Share this post


Link to post
Share on other sites
accessor nie bermaksud apabila sesuatu "member function" nie yg dpt value dr "class memmber" tetapi nilainye x berubah... 2 la accessor..

contoh:-
[code]
class rectangle
{
private:
double width;
double length;
public:
void setWidth(double);
void setLength(double);
double getWidth() const;
double getLength() const;
double getArea() const;
};
[/code]

"member function" getlength dan getWidth 2 la accessors..

kalau nak print out plak...
[code]
double rectangle::getWidth() const
{
return width;
}
[/code]

make sure value da pass dlm function main..

Share this post


Link to post
Share on other sites
kalau kt public tue ade function void print()const...mcm mane nk gune accessor tue dlm function print tue?

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...