473,322 Members | 1,314 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

how to define a function which is declared privately

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
3 1335
willakawill
1,646 1GB
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
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
3,652 Expert 2GB
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

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

Similar topics

17
by: Davor | last post by:
How to define global variable in main()? I'm asking because I have an array in main, whose size is determined by input, so the definition has to be in main ( or in some other funcion ). And I need...
7
by: Peng Yu | last post by:
I'm not very clear about when to use #define and when to use const? #define number 4 const int number = 4; If I just want to define a global constant, which way of the above is better? ...
56
by: Luke Matuszewski | last post by:
I am designing the library, which will hidden all its functions within singleton object ... So for clients they will use it like . eg. system.getElementWithId('ruler'); At library side, i...
4
by: javialmeida | last post by:
Hello everybody. I've been having a look to the c++ FAQ but couldn't get any help there. Does anybody know if is it possible to access a static variable declared within a function?. Something...
29
by: Ancient_Hacker | last post by:
It sure would be nice if I could have a macro that add a level of indirection to its argument. So if I write: AddIndirection( X ) The macro AddIndirection will do: #define X (*X) ...
19
by: Sensei | last post by:
Hi! I'm concerned about the legality of such a definition: #define funcX funcY where funcX belongs to the *standard* C functions. Is it legal to do this? The standard says "any function...
7
by: =?gb2312?B?wfXquw==?= | last post by:
Hi folks, I am running into with such a question when I tried to declare and define a friend template function in a template class, here is the code snippet: #include <iostream> using...
28
by: ravi | last post by:
Hello everybody, I am writing a small application which does some work before the user main function starts execution. I am trying to #define the main function. But the problem is that,
3
by: fortysixfish | last post by:
Hi I've been learning more and more on C/C++ as time goes on. Today I wanted to play around by creating a class that makes it easier to use Windows Tokens. I get stumped though when trying to pass a...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.