SaucyGuy
SaucyGuy

Reputation: 54

Weird error with class integration

So, I'm just starting to learn C++ and I'm learning how to create classes. I've created this code, math.h is a header for a class containing a function called 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;
}

The compiler generates a few errors about functions in the std namespace like: "cout was not declared in this scope"

Here's the code in math.h

#ifndef MATH_H_INCLUDED
#define MATH_H_INCLUDED

int AddTwo(int a)

#endif 

Help? What's going on exactly?

Upvotes: 0

Views: 57

Answers (2)

Bartosz Bosowiec
Bartosz Bosowiec

Reputation: 171

Without a ; after int AddTwo(int a) you usually get a bunch of weird errors.

Upvotes: 3

Andreas DM
Andreas DM

Reputation: 10998

Try this:

#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 

Upvotes: 1

Related Questions