linking problem?

Go4Expert Member
28Nov2006,09:55   #1
Frank Reich's Avatar
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.
Go4Expert Founder
28Nov2006,10:33   #2
shabbir's Avatar
Try adding .h in #include <iostream> or using namespace std
Go4Expert Member
28Nov2006,10:38   #3
Frank Reich's Avatar
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.
Go4Expert Founder
28Nov2006,10:55   #4
shabbir's Avatar
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
Go4Expert Member
28Nov2006,10:59   #5
Frank Reich's Avatar
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.
Go4Expert Founder
28Nov2006,11:04   #6
shabbir's Avatar
Add the following line in the .h file as well

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