By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,804 Members | 1,631 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,804 IT Pros & Developers. It's quick & easy.

how to define a function which is declared privately

P: 6
hi
Expand|Select|Wrap|Line Numbers
  1. class sample{
  2.    private: 
  3.       int num; 
  4.       void sum();
  5.  
  6.    public:
  7.       void get_data();
  8.       void display_data();
  9. };
  10.  
  11. void sample::sum()
  12. {
  13.    //....................
  14.    //....................
  15. }
  16.  
  17. void sample::get_data()
  18. {
  19.    //....................
  20. }
  21.  
  22. void sample::display_data()
  23. {
  24. }
is it right? if yes what is the difference between privately declared funtion and publicly declared function?
Feb 20 '07 #1
Share this Question
Share on Google+
3 Replies


100+
P: 1,646
private means it can only be called from within your class. Public means it can be called from outside the class.
Feb 20 '07 #2

P: 6
private means it can only be called from within your class. Public means it can be called from outside the class.
class sample{
private:
int num;
void sum();
public:
void get_data();
void display_data();
};
void sample::sum()
{
//.............
//....................
}

is it right? if not please tell me how can i define this function out of this class?
Feb 20 '07 #3

Ganon11
Expert 2.5K+
P: 3,652
That looks correct. In declaration and in usage, private and public functions differ as will said, but in definition, you define private functions like public functions.
Feb 20 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.