[英]Why class is giving error when I am creating it using a header and a cpp file of same name of the class
[英]Error in creating a class header file
我正在嘗試創建一個簡單的類頭文件。 到目前為止,我已經完成了以下工作:
#ifndef RECORD_H
#define RECORD_H
class Records{
int idNumber;
int serialNumber;
public:
Records();
};
#endif
但是,我收到以下錯誤:
[錯誤]未知類型名稱'class'
我究竟做錯了什么?
您可能將其編譯為C而不是C ++。 這就是為什么您會收到該錯誤。
確保您的源文件具有.cpp擴展名。
正如lakesh所說,您可能將其編譯為C而不是C ++。 大多數編譯器使用文件擴展名來確定如何編譯文件(使用.cpp
而不是.c
)
如果不是這樣,那么問題可能出在之前的另一個文件中。
// Record.cpp
#include "badfile.h" // error in here
#include "record.h" // error showing up here.
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.