[Gllug] c++ newbie complier probs
Sean Burlington
sean at uncertainty.org.uk
Tue Oct 22 23:02:44 UTC 2002
Jonathan Harker wrote:
>
> #including .cpp files is generally a very bad move. If the ccc stuff is
> written in a half decent style, you should only need to include the .h
> file.
> Generally, you include .h files (which are usually interfaces) and the
> implementation is tucked away in .cpp files; Your compiler/linker will
> magically link the corresponding .o (or if there isn't one, compile a
> fresh
> one from the .cpp).
hmm.. the book I am following seems to have bad style
#include "ccc_empl.cpp"
>
> Secondly, there are two ways to #include something in C++, using < >
> brackets
> or using " " quotes.
DOH !!!
(I knew that bit)
> -I tells the compiler where to look for your .h files
> -L tells the linker where to look for your .o files
using -l doesn't hurt -- but I seem to be able ti complie with just
specifying the include path (is that supposed to work?)
>
> Also, you want to be careful about where you put your using namespace
> statements. Always put them AFTER your #includes, thus:
>
> #include
> #include
> #include "ccc_empl.h"
>
> using namespace std;
unfortunately that doesn't work !
ccc_empl.h doesn't specify any namespace - and only seems to work if I
pollute it by specifying namespace std before including it (its a
slightly old edition - but I have been told in lectures to do it this way !)
>
> Otherwise you pollute ccc_empl.h (and the global namespace - eeek!)
> with std
> names that may clash. using namespace is really only for
> preproduction, debug
> or transitional code, as it clutters your namespaces. Good practice is to
> replace using namespace statements with individual using declarations, or
> tuck them away inside small units such as classes or functions. So, in
> your
> code, you're only using std::cout and std::endl, so your using
> namespace std
> could become
>
> using cout;
> using endl;
>
> Anyway, blah blah blah, what you need to do is:
>
> // #include -- won't work
> // #include -- still won't work
> // #include -- catastrophically bad idea! :-)
>
> #include "ccc_empl.h" // will work! Yay!
>
> then, try this:
>
> g++ -Wall -I/path/to/cccfiles -L/path/to/cccfiles 4.cpp
>
> (You may also want to go -o programname otherwise you'll just get a file
> called a.out)
>
> Hope all that helps! Let me/us know how you get on.
>
> Luv Jon.
ooh - mozillas gone all wierd and hidden the quoted include filenames
from me - I wonder if it will still post OK?
much help thanks
I start to see what I am doing now
and it's always helpfull to know when you are being taught dodgy stuff !
looking ahead in the book - it does include header files -but at a much
later stage
I have to say I was expecting an MSc to be more advanced than this -
even though it is a conversion sourse ..
we have mostly been covering basic stuff like loops and conditionals so
the C++ specific stuff is kind of glossed over (and at the same time we
are studying the IEEE standard for storing floating point numbers in
registers - which seems to me a massive mismatch in detail level)
bizarely #include <ccc_empl.cpp> seems to work
but I'll stick to #include "ccc_empl.cpp"
thanks again
Sean
--
Gllug mailing list - Gllug at linux.co.uk
http://list.ftech.net/mailman/listinfo/gllug
More information about the GLLUG
mailing list