Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Buckys C++ Programming Tutorials - 42 - Arrow Member Selection Operator - YouTube[^]

So you see here he has 3 files: main.cpp, Sally.h and Sally.cpp and he is defining a void function in the Sally.cpp file with syntax void Sally::printCrap(). I got confused in that why he is putting the name of the class for defining a function in outside the class ? Can someone explain me that. I will be really thanksful!

What I have tried:

Sorry for the small and not detailed question but I am limited to 200 characters :X I hope you understood my question and hope you will explain me that.


Thanks!
Posted
Updated 20-May-17 9:56am
v2
Comments
[no name] 20-May-17 14:05pm    
Why aren't you asking "Bucky"?

1 solution

The Sally::printCrap() is because printCrap is defined outside the Class Sally. If it were defined inside the class (inline) it would not have to have Sally::

If you dont have 'Sally::', then the compiler would not know which class the function belonged to.
 
Share this answer
 
v2
Comments
The_Unknown_Member 21-May-17 3:18am    
You mean because it's function prototype is in the Sally class ?
nitrous_007 21-May-17 12:45pm    
Correct
The_Unknown_Member 21-May-17 15:17pm    
Okay very thanks you!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900