开发者

How do I define a function inside of a class using C++?

开发者 https://www.devze.com 2022-12-21 07:05 出处:网络
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:

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消