1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

linking problem?

Discussion in 'C++' started by Frank Reich, Nov 28, 2006.

  1. Frank Reich

    Frank Reich New Member

    Joined:
    Nov 28, 2006
    Messages:
    15
    Likes Received:
    0
    Trophy Points:
    0
    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:
    Could you please let me know, what I am doing wrong?

    Thanks!
    F.R.
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,292
    Likes Received:
    365
    Trophy Points:
    83
    Try adding .h in #include <iostream> or using namespace std
     
  3. Frank Reich

    Frank Reich New Member

    Joined:
    Nov 28, 2006
    Messages:
    15
    Likes Received:
    0
    Trophy Points:
    0
    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.
     
  4. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,292
    Likes Received:
    365
    Trophy Points:
    83
    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
     
  5. Frank Reich

    Frank Reich New Member

    Joined:
    Nov 28, 2006
    Messages:
    15
    Likes Received:
    0
    Trophy Points:
    0
    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.
     
  6. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,292
    Likes Received:
    365
    Trophy Points:
    83
    Add the following line in the .h file as well

    #include <iostream>
    using namespace std;
     
  7. Frank Reich

    Frank Reich New Member

    Joined:
    Nov 28, 2006
    Messages:
    15
    Likes Received:
    0
    Trophy Points:
    0
    Okay. this one works. But how do I get 'DIM' into the cTest class without writing the definition a second time?
     
  8. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,292
    Likes Received:
    365
    Trophy Points:
    83
    Define it in the .h file instead of .cpp file.
     

Share This Page