Question:
C++ classes in C++ primer by stanley B Lippman?
Akshat
2013-06-26 14:30:34 UTC
I've started with c++ in school some time back. I read the textbook and classes were defined as

Type classname { members.
}

But i started reading the book C++ primer and its is completely different there. That type of classes are nowhere even on the internet.

Its like # include "sales_item.h"

.
.
.
.
Sales_item item 1 , item 2;


And member functions is also very weired.

And too we write # include but here .h is not written. Pls help.
Three answers:
husoski
2013-06-26 15:06:43 UTC
To get a mostly complete implementation of C++11 and an IDE comparable to Turbo C++, try Code::Blocks.

http://www.codeblocks.org



For Windows, get the binary that include the MinGW compiler and that will give you everything you need to edit, compile and debug C or C++ programs and libraries.

http://www.codeblocks.org/downloads/26



You can also use Visual Studio Express as a free download from Microsoft. That's not open-source, and it takes some extra undocumented steps to set up a standard C or C++ project. The pre-installed templates all have MS-specific settings that won't compile pure standard C or C++ source, and boilerplate code it generates won't compile in a standard compiler.



However, you can take those extra steps and get a nicer debugger, and some excellent troubleshooting support in debug builds. I use both.

http://www.microsoft.com/visualstudio/eng/products/visual-studio-express-products



Get the 2012 Desktop version for general programming in C/C++, VB or C#. Scroll down to the 2010 version links if you need to run on XP or Vista...2012 only runs on 7 or 8.
_Object
2013-06-26 22:31:26 UTC
I don't know what kind of C++ that was. :)

C++ has had clearly defined standards for a long time; nowhere was there any "Type" keyword.

Even so, all C++ keywords are lower-case.



Lippman's book is reasonably old, isn't it?

But if it mentions the C++11 Standard from a near-future or present standpoint than you'll be okay.



Iostream.h is an old, deprecated, (originally nonstandard) header that was developed as a type-safe IO. The extensionless version is up to date, and standardised.

A very brief article about the differences:

http://members.gamedev.net/sicrane/articles/iostream.html

C++11 support is finally reaching completion.

I would suggest GCC, the GNU Compiler Collection. It's widely portable, completely up-to-date, and is mostly or completely standards-compliant (most compilers are not).

Here:

http://gcc.gnu.org/

This is my favorite compiler, unfortunately I'm stuck with Microsoft's proprietary cl.exe now. (This is Visual Studio, the professional version, as linked somewhere above my post)



As for private versus protected:

Private denies access to all non-members, including subclasses (derivations) inheriting with public.

Protected denies access to all non-members, but is accessible down the inheritance chain.



When you need to propagate a function or field that should be private down a inheritance chain, you should declare that method as protected. This way it's not exposed to the outside world.
2013-06-26 21:36:25 UTC
The newest way to include the iostream library is to do it without the .h. Such as

#include "



The include function with the quotes around it instead of brackets is a custom header, meaning one you write yourself and include into the project solution.



Sales_item item1, item2;

This is who you declare objects. Sales_item would the class name and item1 and item2 are the "variables" of that type. Member functions looks the same as regular functions except they might have modifiers like the static or virtual keyword which you can find: http://www.cplusplus.com/doc/tutorial/polymorphism/


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...