Jump to content
Larry Ullman's Book Forums

Linkage And Scope Scripts - Chapter 12


Recommended Posts

Hi,

 

I am back 'into' the C++ book :-)

 

I tried to get the scripts 12.8, 12.9 and 12.10 to work in my Dev-C++ 5.8.3 IDE but it seems not to take any notice of the pre-processor directives in the header file as I get a compile error 'multiple definitions of headerNum'; specifically that headerNum is first defined in that.cpp with a consequent multiple definition in this.cpp.

 

However, I can get it to work in my MS Visual C++ 2008 IDE but I needed to add #include "stdafx.h" in both this.cpp and that.cpp and also change the definition of headerNum as per the errata for the book.

 

My environment is Windows 7, 64 bit.

 

Could it be that my Dev-C++ IDE somehow ignores or doesn't recognise the C pre-processor directive?

 

Any advice will be most appreciated, and thankyou in anticipation.

 

Cheers from Oz.

Link to comment
Share on other sites

I just kept 'fiddling' and by placing the #include "header.h" directive in front of the #include <iostream> directive in script 12.10 (this.cpp), it worked???

 

The code now looks like this:

 

 

// this.cpp - Script 12.10
// Need the header file.
#include "header.h"
#include <iostream>
// Get the external variable.
extern unsigned short thatNum;
// Create a static variable.
static bool printMe = false;
int main() {
...etc...

 

and the definition of headerNum is as per the errata guidance - static const unsigned short headerNum = 5;

 

In case anyone else comes across this oddity!

 

Cheers from Oz.

Link to comment
Share on other sites

 Share

×
×
  • Create New...