linking problem?

Frank Reich's Avatar
Go4Expert Member
Morning!

I am facing a small problem with the following code:
Code:
#include <iostream>

#define DIM 1

#include "cTest.h"

int main()
{
	return 0;
}
and here the cTest.h-file:
Code:
#pragma once

#ifndef CTEST_H
#define CTEST_H

class cTest
{
public:
	cTest(void);
	~cTest(void);
	void Count ()
	{
		cout << DIM;
	}
};

#endif
Now I am getting the following errors:
Quote:
error C2065: 'DIM' : undeclared identifier
error C2065: 'cout' : undeclared identifier
Could you please let me know, what I am doing wrong?

Thanks!
F.R.
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Try adding .h in #include <iostream> or using namespace std
0
Frank Reich's Avatar
Go4Expert Member
Dear shabbir,

thanks for the reply. But:

1.) #include <iostream> is the new standard. adding .h is not used any more.
2.) using namespace std was not working, still the same erros are coming up

But thanks.
F.R.
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
What compiler you are using which gives error on adding "using namespace std". If it gives error for "using namespace std" that does mean you need to include the file using the older method of .h
0
Frank Reich's Avatar
Go4Expert Member
Hi.

I am using VC++8.0, so there shouldn't be any problem with including 'using namespace std;'.

What i meant is, that even including this line, the errors mentioned in my first post don't disappear.

F.R.
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Add the following line in the .h file as well

#include <iostream>
using namespace std;
0
Frank Reich's Avatar
Go4Expert Member
Okay. this one works. But how do I get 'DIM' into the cTest class without writing the definition a second time?
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Define it in the .h file instead of .cpp file.