External Class w/ namespace error

I have been trying to link files and headers with classes, but dev-cpp keeps throwing an error concerning lines in the namespace std

I have three simple files to test use of an external class:

test.h
1
2
3
4
5
6
7
8
9
10
11
#ifndef TEST_H
#define TEST_H

class cl{
   int i;
   public:
     void set(int si);
     int get();
}

#endif 


test.cpp
1
2
3
4
5
6
7
8
9
#include <iostream>

void cl::set(int si) {
   i=si;
}

int cl::get(){
   return i;
}


main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
#include "test.h"
#include <iostream>
using namespace std;

class cl;
cl c;

int main() {
   c.set(1);
   cout << c.get();
   cin.get();
   return 1;
}


and when this compiles, I get 5 namespace std source file errors (in c++config.h) and 1 makefile.win error.

I am using Dev-C++ for lack of better compiler, is this a compiler or user error?

Although there is lots of material about external files, none I've found address my issue . . .
Delete "class cl" in main.cpp

And add a ';' right after } in test.h. (this is probably causing the weird errors)

And add #include "test.h" in test.cpp
Last edited on
Everything looks correct except line #5 in main.cpp. It must be deleted.
For what it's worth you also don't need #include <iostream> in test.cpp
Thanks Jikax, that worked, I'll see if something similar's my problem in my bigger project (almost 400 lines of code).
Topic archived. No new replies allowed.