在标头(.h)中声明构造函数,然后在类文件(.cpp)中定义C ++的语法

在标头(.h)中声明构造函数,然后在类文件(.cpp)中定义C ++的语法

问题描述:

如果有人可以提出这个建议,我将不胜感激.我认为可行的示例(假设所需的#include语句在其中):

If anyone could lay this out, I would appreciate it. Example of what I thought would work (assume the needed #include statements are there):

//.h file
class someclass(){}

//.cpp
someclass::
    someclass(){
         //implementation
         // of 
         //class
};

someclass.h文件

someclass.h file

#ifndef SOME_CLASS_H
#define SOME_CLASS_H    

class someclass
{
public:
  someclass();  // declare default constructor

private:
  int member1; 
};

#endif

someclass.cpp

someclass.cpp

someclass::someclass()   // define default constructor
: member1(0)             // initialize class member in member initializers list
{
   //implementation
}