类集成的奇怪错误

时间:2014-12-14 17:39:50

标签: c++

所以,我刚开始学习C ++,我正在学习如何创建类。 我创建了这段代码,math.h是包含一个名为AddTwo的函数的类的头文件。

#include <iostream>
#include "math.h"

using namespace std;


int main()
{
    int number;
    cout << "Gimme a number: ";
    cin >> number;
    cout << number << " plus 2 is " << AddTwo(number) << endl;
}

编译器在std命名空间中生成一些关于函数的错误,如:“cout未在此范围内声明”

这是math.h中的代码

#ifndef MATH_H_INCLUDED
#define MATH_H_INCLUDED

int AddTwo(int a)

#endif 

帮助?到底发生了什么?

2 个答案:

答案 0 :(得分:3)

;之后没有int AddTwo(int a)你通常会遇到一堆奇怪的错误。

答案 1 :(得分:1)

试试这个:

#ifndef MATH_H_INCLUDED
#define MATH_H_INCLUDED
// If you define the function in a separate cpp file,
// then you just forgot the semicolon
// else define it here:

int AddTwo(int a)
{
    return a + a;
}

//
#endif