Suddenly Can't Use "ifstream"s and "ofstream"s

K

KevinSimonson

I had a working piece of code that successfully read from files with
the "ifstream" type and wrote to files with the "ofstream" type. This
code is made up of a number of different files. In the course of the
job I needed for two of these files to have access to one piece of
information, so I created a class that I called "CSuffix" and stored
the common information there. So I created a "Suffix.h" file that
looks like:

#pragma once

class CSuffix
{
public:

static void initialize ();

static void increment ();

static char* latest ();
}

That's it in its entirety. Now I put a line that says, '#include
"Suffix.h"' among my includes, right before the line that says,
'#include <iostream>'. And all of a sudden the compiler doesn't
recognize either my "ifstream"s or my "ofstream"s. All I have to do
is comment out the line that says, '#include "Suffix.h"' and then all
my "ifstream"s and "ofstream"s start working again (although obviously
the compiler then complains about my calls to my three "CSuffix"
methods). So it looks to me like I must be doing something wrong in
my "Suffix.h" file. Can anyone see what the problem is?

Kevin S
 
K

KevinSimonson

Missing semicolon?

/Leigh

Thank you! Thank you! That solved the problem. Makes me wonder
though; why does the code _need_ a semicolon at the end of a header
file? I don't put a semicolon at the end of a class implementation,
and that always compiles just fine.

Kevin S
 
V

Vaclav Haisman

KevinSimonson wrote, On 4.11.2010 2:11:
Thank you! Thank you! That solved the problem. Makes me wonder
though; why does the code _need_ a semicolon at the end of a header
file? I don't put a semicolon at the end of a class implementation,
and that always compiles just fine.
It never compiles fine. You must be seeing things or using something else
than C++ compiler to compile it.
 
J

Juha Nieminen

In comp.lang.c++ Pete Becker said:
A semicolon is required at the end of a class definition.

And the reason for that is because this is valid:

class A
{
/* something here */
} instance;

The semicolon is needed to distinguish between a normal class definition
and that.

Many C++ programmers don't even know this, and don't really even
understand what that means, and it's admittedly something you
extremely seldom (if ever) see in C++ programs, and it exists almost
solely as baggage from C (where using it with structs is more common).
 
J

James Kanze

And the reason for that is because this is valid:
class A
{
/* something here */
} instance;
The semicolon is needed to distinguish between a normal class
definition and that.
Many C++ programmers don't even know this, and don't really
even understand what that means, and it's admittedly something
you extremely seldom (if ever) see in C++ programs, and it
exists almost solely as baggage from C (where using it with
structs is more common).

It crops up from time to time in my code, when using local
classes. And I've seen it occasionally in other people's code
as well. Globally, I'd say it's more common in C++ (where most
cases involve a derived class) than in C.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top