How do I 开发者_JAVA百科define a function inside of a class using C++?
There are 2 answers:
1) Combining both the declaration and the definition:
class C
{
public:
//declaration and definition of f
void f()
{
}
};
2) Separating the declaration and the definition:
class C
{
public:
//declaration of f
void f();
};
//definition of f
void C::f()
{
}
Typically in option #2 you would separate the declaration into a header file and the definition inside a source file.
Simple ans:when we write the function within the class with his body is known as function declaration and defination with in the class.
Defination of function outside the class:when we write the function name outside the class by the help of scoperesulation operator is called function defination outside the class.
精彩评论