【发布时间】:2014-01-16 23:49:30
【问题描述】:
我刚刚开始学习 C++ 类、构造函数和函数,但如果我理解正确的话,我就不是这样了。我的代码没有问题,因为它工作正常,我只是对哪个位是哪个位感到困惑,我在代码中添加了我认为正确的 cmets。如果有人能解释我的错误和/或正确,我将不胜感激。谢谢。
这是 Main.cpp,我完全理解为文件:
#include "Something.h"
#include <iostream>
using namespace std;
int main(){
Something JC;
system("PAUSE");
return 0;
}
这是Something.cpp:
#include "Something.h"
#include <iostream>
using namespace std;
//Something is the class and :: Something() is the function?
Something::Something()
{
cout << "Hello" << endl;
}
这是Something.h:
// this is a class which is not within the main.cpp because it is an external class?
#ifndef Something_H
#define Something_H
class Something{
public:
Something(); //constructor?
};
#endif
我只是想知道哪个是哪个,如果我错了。
【问题讨论】:
标签: c++ function class constructor