tags:

views:

274

answers:

7

I'm just being introduced to C++, and want to know a basic question.... What happens when using C++? Is there anywhere I can see a working example? Textbooks break it down, segment by segment. I would really like to SEE what happens. ANY suggestion would be appreciated. Hope MY question is not too vague. Thanks!

+2  A: 

If you are trying to learn C++, you cannot just read from the textbook -- programming is learned best through hands-on practice. You should get a C++ compiler and run through the textbook examples yourself.

Jimmy
Sing it, brother. This is absolutely the best advice. There's a huge difference between "book smarts" and working experience when it comes to this beast of a language.
Dan
A: 

Sounds like a short session with your TA (at an American university, this is the graduate student who helps with the hands-on stuff, does the grading, etc., as a help to the professor) is in order. Get him/her to show you how to use whatever IDE (integrated development environment) your class is requiring/suggesting. Or wait for your lab session, where you will learn this.

kajaco
A: 

You can use a debugger to execute your program step by step, looking at the variables. If that's not enough, debuggers can also show you the a disassembled version of the machine code along with the processor's registers.

Would that help?

sbi
+6  A: 

You get into the office around 8:30am, get some tea, and you sit down and run a program called an IDE. It lets you type code with the keyboard, such as:

(*m_pHopeThisIsntNull)->doIt();

You can then hit F5 and the code runs and you find out it doesn't work the way you expected. Pretty soon it's 5:30pm.

Daniel Earwicker
One string a day... I thought it is good for ASM developers, not for C++ :)
Kirill V. Lyadvinsky
No, a line of C++ takes weeks to get right! For example, I imagine that line is calling the overloaded `*` operator on a type which returns a type that overloads the `->` operator, which returns another type that returns the `->` operator, which returns a type that has a public member variable called `doIt`, which is of a type that overloads the `()` operator to return a temporary that constructs and then immediately destructs.
Daniel Earwicker
@Earwicker +1 if you can show me an example of that in action. :P
Jeremy Powell
@Jeremy - wasn't intended as a serious criticism of C++, you can hide complexity in a small space in any powerful language. In C# the expression `() => x` effectively declares two classes all by itself.
Daniel Earwicker
A: 

You are using C++! your browser is written in C++!

AraK
Not the code it self of course :)
AraK
A: 

When I use C++, other programmers bow down to me because of my awesomeness. But that's just my experience.

Larry Watanabe
A: 

If you want to see it step by step:

Set a breakpoint at the first line and start in debug (F5 in Visual Studio). You can step through the program step-by-step and see what's going on with varying granularity (Step Over or Step Into - usually F10 and F11 in Visual Studio). Stepping into will follow a function call whereas F10 will call it, and step forward over it after it returns.

If you want to see what's going on at a lower level you can use disassemble on your code.

I've used Visual Studio/Windows stuff here b/c that's what I'm most used to but these things are in every major C++ IDE I've seen.

McAden