g++ compile warning: extra tokens at end of #include directive

J

japh

I just started learning c++ and am at the point of using:

#include "myclass.cpp"

instead of having the class definition in the main file. But I am
getting this warning at compile time:

cat.cpp:4:19: warning: extra tokens at end of #include directive

The program compiles and runs fine, but the warning is puzzling and
concerns me. A google search returned lots of matches but no
solutions...

Any ideas? thanks
 
M

Mike Hewson

japh said:
I just started learning c++ and am at the point of using:

#include "myclass.cpp"

instead of having the class definition in the main file. But I am
getting this warning at compile time:

cat.cpp:4:19: warning: extra tokens at end of #include directive

The program compiles and runs fine, but the warning is puzzling and
concerns me. A google search returned lots of matches but no
solutions...

Any ideas? thanks

You'd put the interface/declarations in say "myclass.h" and include
that. The definitions are in "myclass.cpp" and get added to your compile
( and link ) list for the project.

<aside>

ISO/IEC 14882:1998(E) © ISO/IEC
16.2 Source file inclusion
..
..
5 The mapping between the delimited sequence and the external source
file name is implementation defined. The implementation provides unique
mappings for sequences consisting of one or more nondigits (2.10)
followed by a period (.) and a single nondigit. The implementation may
ignore the distinctions of alphabetical case.

<end aside>
 
J

japh

Yeah - I guess I wasn't precise in describing the problem. I do have a
header file, etc. The problem seems to be with including files.
#include <iostream> works fine.

#include "myheader.hpp"; yields a warning but still works.
I'm using g++ on FreeBSD

Thanks
 
J

japh

DOH -- pretty simple error:

I was typing
#include "myclass.hpp";

instead of
#include "myclass.hpp"

It turns out the semi-colon was the problem.
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top