因此,這裏是我的代碼:頭文件沒有被讀取?
主要
#include<iostream>
#include "Tclass.h"
#include "Tclass.cpp"
using namespace std;
int main(){
int x = 7;
Tclass object;
cout << object.OFunction();
return 0;
}
頭文件
#ifndef TCLASS_H
#define TCLASS_H
class Tclass
{
public:
Tclass();
int OFunction();
};
#endif // TCLASS_H
C++樣式表(我相信這是它叫什麼)
#include "Tclass.h"
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
Tclass::Tclass()
{
cout << "An object for this class has been created \n";
}
int Tclass::OFunction(){
srand(time(0));
return 1+(rand()%6);
}
我問題是我聽說我不需要包含#include"Tclass.cpp"
在我的代碼,但沒有它我的代碼將無法運行。另外我從主目錄中刪除頭文件仍然有效。我相信這個人是正確的,但我根本無法得到這個工作。我使用的IDE是code :: blocks。