Ye Olde General C++ Discussion/Advice Thread

Holey moley Jans, when did you get around to be a programming guru on the side??? Very impressed.

And thanks for that detailed explanation Zippy. Just two quick questions for you:
1: Just so that I can be sure to use the file types you displayed accurately, what is the difference between the code in a .hpp and .cpp file?
2: Can you please look at my first real C++ program, and advise if there's anything I could have done differently to make it more efficient? I'm proud of actually using a for loop to write and read from an array, but I think I'm hacking it a little bit (especially my use of 'break;' to get it to stop at one point).

apologies I misread your first question.

The hpp file is the class interface and cpp is the class implementation
 
Whoohoo, thanks Swa and Zippy. It's like my very own interactive textbook :)

Stackoverflow is seriously useful too ... it seems like whatever question I have, somebody's already asked it (and gotten a dozen seriously confusing answers).

I guess the 'compile' issue only becomes serious with major programs, where they start taking a serious amount of time to compile the whole thing each time, compared to only compiling the new bits. Right now it's a non-issue for me, but I'd better learn the right way like's been suggested here.
 
Whoohoo, thanks Swa and Zippy. It's like my very own interactive textbook :)

Stackoverflow is seriously useful too ... it seems like whatever question I have, somebody's already asked it (and gotten a dozen seriously confusing answers).

I guess the 'compile' issue only becomes serious with major programs, where they start taking a serious amount of time to compile the whole thing each time, compared to only compiling the new bits. Right now it's a non-issue for me, but I'd better learn the right way like's been suggested here.

Actually what makes the difference is not really that there is hpp or h file, but rather the #indef, #define and #endif lines in hpp or h files. And most compilers dont like these directives in the cpp files.

There is also a #pragma once directive, but its compiler specific and should be avoided. I think Visual Studio automatically uses #pragma once if use the class wizard.


Also, for large projects avoid using :

Code:
namespace std;

Just type out the full std::cout etc.

Doesnt matter for small projects. Some coders are more militant about it than others.
 
Whoohoo, thanks Swa and Zippy. It's like my very own interactive textbook :)

Stackoverflow is seriously useful too ... it seems like whatever question I have, somebody's already asked it (and gotten a dozen seriously confusing answers).

I guess the 'compile' issue only becomes serious with major programs, where they start taking a serious amount of time to compile the whole thing each time, compared to only compiling the new bits. Right now it's a non-issue for me, but I'd better learn the right way like's been suggested here.
Yes but major is a relative term here. Doing programming on a camera hack which is still quite small compared to really large projects. The environment for some reason is set up so it recompiles every file and not just the one I changed. Takes about 5 minutes to compile it all. I don't know enough about configuring the compiler and the different camera models or I'll use a make file to do it.
 
lol. Im spoilt by Objective-C and xcode's, profiling tools :) I try my harderst to avoid this type of thing : MyCube* cube = new MyCube();

*sighs* Ok, that little in-joke officially makes me feel like a toddler sitting in a University lecture.

At least *try* pretend it's gonna be easy to learn :P
 
*sighs* Ok, that little in-joke officially makes me feel like a toddler sitting in a University lecture.

At least *try* pretend it's gonna be easy to learn :P

Its not really that hard. Its all about practice. It only looks daunting because you are starting out. I actually learnt Objective-C before I learnt C++

One of the reasons I prefer the Xcode IDE to Visual Studio. Just more familiar with it. I wouldnt really rank languages in terms of their difficulty in learning. Rather I would rank them in how easy it is to screw something up and then how hard it is to find the problem. With this method I would rank as follows, with easiest to screw up and hardest to debug at the top

1. C
2. C++
3. Java
4. Objective-C

In terms of difficulty in grasping they aren't really that different. Just that someone is more likely to get the hell in with finding bugs in C and C++ :)

I think the C++ and Objective-C are more fun though :P
I find Java terribly boring.
 
backstreetboys example is fine.

There are many ways of doing it. One alternative is to use vector of a vector. But for what you are doing its overkill, but it might be good way of learning some of the more advanced things in the standard template library (STL). std::vector

look at http://www.codeguru.com/cpp/cpp/cpp...ial-A-Beginners-Guide-to-stdvector-Part-1.htm

It has many advantages over arrays. Arrays are more C than C++ :)

wtf vector of vectors lol xD

lol. Im spoilt by Objective-C and xcode's, profiling tools :) I try my harderst to avoid this type of thing : MyCube* cube = new MyCube();

:p

*sighs* Ok, that little in-joke officially makes me feel like a toddler sitting in a University lecture.

At least *try* pretend it's gonna be easy to learn :P

learn about the stack and the heap and know the difference and where memory is allocated in different ways.

By declaring a pointer:

MyCube* cube

and assigning to it the reference of newing an instance of MyCube he is creating memory on the heap, in c++ you need to manage this memory and dispose of it and clear the pointer after, or use smart pointers.

I think he knows that though just giving him cr@p
 
wtf vector of vectors lol xD



:p



learn about the stack and the heap and know the difference and where memory is allocated in different ways.

By declaring a pointer:

MyCube* cube

and assigning to it the reference of newing an instance of MyCube he is creating memory on the heap, in c++ you need to manage this memory and dispose of it and clear the pointer after, or use smart pointers.

I think he knows that though just giving him cr@p

Where can I learn something like this in an easy-to-digest fashion, outside of University? There are endless tutorials online, but they all seem to jump straight into programming, and they don't provide the all-important basic framework (the why and what not to do).
 
Where can I learn something like this in an easy-to-digest fashion, outside of University? There are endless tutorials online, but they all seem to jump straight into programming, and they don't provide the all-important basic framework (the why and what not to do).

buy the unisa text book for COS1511 from takealot
 
Foxhound C is a great language to get started, and especially to teach you best practice (keeping track of your trash for e.g.). If you want to see more bang for your buck however, I recommend Java since all the functionality is included, but not compulsory. It's a good way of working with standard libraries and getting a hang of overrides and the super concept, as applied to classes (object-oriented programming). Everything is just self-explanatory, and there is no profit-incentive like with Microsoft's dead-eyed documentation which will leave you decidedly chilled.
 
Jan wtf are you even on about. Microsoft give away visual studio now. Which is far superior to any other ide out there. And as for documentation msdn is very well written.
 
There are way better IDEs than Visual Studio. Problem is that most of them are application specific like Qt SDK for example. Still VS also teaches to use proprietary MS stuff like MFC and .NET which makes code incompatible and less portable.
 
There are way better IDEs than Visual Studio. Problem is that most of them are application specific like Qt SDK for example. Still VS also teaches to use proprietary MS stuff like MFC and .NET which makes code incompatible and less portable.

I've used a lot of IDEs, and never found one better than Visual Studio.

MS is becoming a lot more open in this regard, too.
 
Top
Sign up to the MyBroadband newsletter
X