RE: GCC Compile Failure

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Welcome to C++!
I know this is a gcc maillist and not one for C++ specifically, but I'm going to clarify things using the C++ standard.  I highly recommend you get a copy of this and get used to referencing it - it's heady stuff, and overwhelming at first (and for some time afterward), but it is the standard and can steer you clear of a LOT of "well-intentioned-but-bad" advice available on the web and in forums.  To help you sort through things from a practitioner's (rather than "language lawyer") perspective, there are a few good references - I use C++ Primer (now in 4th ed., by Lippman, Lajoie, and Moo) most often.

As was previously pointed out, cout is an object, not a function.  You need to "#include <iostream>" to pick up the definition - see C++ Std - 27.3.  As was also pointed out, C++ std library include files don't have an extension (officially, again, certain implementations continue to support legacy, non-standard extensions).  (C++ Std. 17.4.1.2)

In addition, although it will work with "#include <stdio.h>", I'd recommend using "#include <cstdio>" and change the printf to std::printf.  (Or simply declare "using namespace::std;" and drop all the "std::" prefixes.  When you get a chance, you may want to look at "namespaces" in a good C++ reference.
See appendix D - D.5 in the C++ std and section 17.4.1.2 for details.

Finally, as a good programming practice, do not rely on the "implicit int return" - declare main as "int main( )".  BTW - you may see a lot of examples out there with different prototypes/signatures for main - there are only two "official" signatures for this function (and "int main( )" is one of them) - see C++ Std - 3.6.1 paragraph 2.


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux