Using Windows XP
Visual C++ Express 2008 (free version)
I get the following unexpected end of file message when entering code straight from the book "Exploring C++ / Ray Lischner" (email the author claims is his in the book doesn't exist, and there is no book web forum):
------ Build started: Project: ch39_1, Configuration: Debug Win32 ------
Compiling...
generate_id.cpp
c:\documents and settings\ralf becker.ralf_work\my documents\visual studio 2008\projects\c++\ch36_42\ch39_1\ch39_1\generate_id.hpp(14) : fatal error C1004: unexpected end-of-file found
main.cpp
c:\documents and settings\ralf becker.ralf_work\my documents\visual studio 2008\projects\c++\ch36_42\ch39_1\ch39_1\generate_id.hpp(14) : fatal error C1004: unexpected end-of-file found
Generating Code...
Build log was saved at "file://c:\Documents and Settings\Ralf Becker.RALF_WORK\My Documents\Visual Studio 2008\Projects\c++\ch36_42\ch39_1\ch39_1\Debug\BuildLog.htm"
ch39_1 - 2 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
The code is as follows - a header file for a class; a .cpp file for the related member functions; and a main.cpp file (very short as just learning about concepts):
generate_id.hpp
#ifndef GENERATE_ID_HPP_
#define GENERATE_ID_HPP_
class generate_id
{
public:
generate_id() : counter_(0) {}
long next();
private:
short counter_;
static short prefix_;
static long int const max_counter_ = 32767;
};
#endif
generate_id.cpp
#include "generate_id.hpp"
short generate_id::prefix_(1);
long const generate_id::max_counter_;
long generate_id::next()
{
if (counter_ == max_counter_)
counter_ = 0;
else
++counter_;
return prefix_ * (max_counter_ + 1) + counter_;
}
main.cpp
#include <iostream>
#include <ostream>
#include "generate_id.hpp"
int main()
{
generate_id gen;
for (int i = 0; i!= 10; ++i)
std::cout << gen.next() << '\n';
}
I realize that typical solutions to this problem include:
(a) Check all braces etc. close properly, and
(\
check if any precompiled headers are used (they are not - option is disabled).
I am obviously learning C++, so maybe this is just trival for you guys. What throws me off is that the program compiles and runs 100% fine if the pre-compiler commands #ifndef/#define/#endif are removed; output produced then is as expected:
32769
.
.
.
32778
So the error only starts when adding the precompiler #conditionals. However, the IDE recognizes the conditional proper, as witnessed by...
- producing a 'missing #endif' error if i remove #endif (just to check it), and
- by indicating that #endif corresponds to #ifndef in the usual IDE way (brief blinking of #ifndef after entering #endif)
Sorry for being verbose but meant to provide info as precisely as I could. Any help would be greatly appreciated. Throws me off quite a bit if i got trouble using such precompiler commands.
Best, OGtR.
Visual C++ Express 2008 (free version)
I get the following unexpected end of file message when entering code straight from the book "Exploring C++ / Ray Lischner" (email the author claims is his in the book doesn't exist, and there is no book web forum):
------ Build started: Project: ch39_1, Configuration: Debug Win32 ------
Compiling...
generate_id.cpp
c:\documents and settings\ralf becker.ralf_work\my documents\visual studio 2008\projects\c++\ch36_42\ch39_1\ch39_1\generate_id.hpp(14) : fatal error C1004: unexpected end-of-file found
main.cpp
c:\documents and settings\ralf becker.ralf_work\my documents\visual studio 2008\projects\c++\ch36_42\ch39_1\ch39_1\generate_id.hpp(14) : fatal error C1004: unexpected end-of-file found
Generating Code...
Build log was saved at "file://c:\Documents and Settings\Ralf Becker.RALF_WORK\My Documents\Visual Studio 2008\Projects\c++\ch36_42\ch39_1\ch39_1\Debug\BuildLog.htm"
ch39_1 - 2 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
The code is as follows - a header file for a class; a .cpp file for the related member functions; and a main.cpp file (very short as just learning about concepts):
generate_id.hpp
#ifndef GENERATE_ID_HPP_
#define GENERATE_ID_HPP_
class generate_id
{
public:
generate_id() : counter_(0) {}
long next();
private:
short counter_;
static short prefix_;
static long int const max_counter_ = 32767;
};
#endif
generate_id.cpp
#include "generate_id.hpp"
short generate_id::prefix_(1);
long const generate_id::max_counter_;
long generate_id::next()
{
if (counter_ == max_counter_)
counter_ = 0;
else
++counter_;
return prefix_ * (max_counter_ + 1) + counter_;
}
main.cpp
#include <iostream>
#include <ostream>
#include "generate_id.hpp"
int main()
{
generate_id gen;
for (int i = 0; i!= 10; ++i)
std::cout << gen.next() << '\n';
}
I realize that typical solutions to this problem include:
(a) Check all braces etc. close properly, and
(\
I am obviously learning C++, so maybe this is just trival for you guys. What throws me off is that the program compiles and runs 100% fine if the pre-compiler commands #ifndef/#define/#endif are removed; output produced then is as expected:
32769
.
.
.
32778
So the error only starts when adding the precompiler #conditionals. However, the IDE recognizes the conditional proper, as witnessed by...
- producing a 'missing #endif' error if i remove #endif (just to check it), and
- by indicating that #endif corresponds to #ifndef in the usual IDE way (brief blinking of #ifndef after entering #endif)
Sorry for being verbose but meant to provide info as precisely as I could. Any help would be greatly appreciated. Throws me off quite a bit if i got trouble using such precompiler commands.
Best, OGtR.

Help
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.

Back to top









