Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C++ (http://www.go4expert.com/forums/cpp/)
-   -   linking problem? (http://www.go4expert.com/forums/linking-problem-t2037/)

Frank Reich 28Nov2006 09:55

linking problem?
 
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.

shabbir 28Nov2006 10:33

Re: linking problem?
 
Try adding .h in #include <iostream> or using namespace std

Frank Reich 28Nov2006 10:38

Re: linking problem?
 
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.

shabbir 28Nov2006 10:55

Re: linking problem?
 
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

Frank Reich 28Nov2006 10:59

Re: linking problem?
 
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.

shabbir 28Nov2006 11:04

Re: linking problem?
 
Add the following line in the .h file as well

#include <iostream>
using namespace std;

Frank Reich 28Nov2006 11:09

Re: linking problem?
 
Okay. this one works. But how do I get 'DIM' into the cTest class without writing the definition a second time?

shabbir 28Nov2006 11:20

Re: linking problem?
 
Define it in the .h file instead of .cpp file.


All times are GMT +5.5. The time now is 15:25.