【发布时间】:2013-11-10 17:29:47
【问题描述】:
我现在正在学习头文件和类,但我似乎无法让它们工作。我看不出我做错了什么。我已将错误包含在编译器说有错误的 cmets 中。我该如何解决这个问题?
main.cpp
#include <iostream>
#include <conio.h>
#include "Header.h" //Error: In file included from C:\Users\Brandon\Desktop\
C++ Practice\Header Practice\Main.cpp
int main()
{
Header Test;
Test.Header(); Error: invalid use of `class Header'
getch();
return 0;
}
头文件.h
#ifndef Header_H_
#define Header_H_
class Header
{
public:
void Header(); //Error: return type specification for constructor invalid
};
#endif // Header_H_
和 Header.cpp。
#include "Header.h"
Header::Header()
{
std::cout << "Everything is working./n" << std::flush;
};
【问题讨论】:
-
构造函数没有类型说明符。从 Header.h 中的
void Header();中删除void