c++ - 将类放在单独的文件中时无法调用函数

标签 c++

<分区>

所以我是 C++ 的新手,我试图创建一个函数来在用户输入底边和高度时计算三角形的面积,但是每当我尝试构建和运行这个程序时,我都会收到一条错误消息:ISO C++ 禁止声明没有类型的“calcArea”[-fpermissive]

区域.h

#ifndef AREA_H
#define AREA_H
#include <iostream>
using namespace std;


class Area
{
    private:
        int base;
        int height;
    public:
        Area();
        int calcArea();


};
#endif // AREA_H

面积.cpp

#include "Area.h"
#include <iostream>
using namespace std;

Area::Area()
{
    cin >> base;
    cin >> height;
};

Area::calcArea(){
int answer;
answer = base * height;
return answer;

}

最佳答案

您缺少返回类型。

  int Area::calcArea(){
//^^^

关于c++ - 将类放在单独的文件中时无法调用函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25656507/

相关文章:

c++ - 非常量指针类型的参数不调用带有常量指针模板类型参数的函数

C++ 返回类型限定符天堂

c# - 设计——按名称或对象删除?

c++ - Fortran 和 C++ : Linking error in Visual Studio

c++ - Ncurses 输出函数只接受常量数据

c++ - 获取 vector 的内容并将它们放入文本文件中

c++ - 为什么 GCC 4.8.2 不传播 'unused but set' 优化?

c++ - Qt 气球小部件掩码

c++ - 如何在SFML中使用俄语文本?

c++ - 系统 libc 文件的 Clang 工具链失败