本文介绍了在标头(.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
}

这篇关于在标头(.h)中声明构造函数,然后在类文件(.cpp)中定义C ++的语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 07:40