Help with OOP

Hello. I am 14 and I have been learning c++ for about 2 months, and I have now gotten to the object oriented programming part of c++. I use Codeblocks and a book to learn c++. Everything else Ive been able to learn, replicate, and expand upon , except oop. I especially have trouble with classes. Are there any tips I can have? Or am I doing something wrong by learning a bit, then writing code with that? Should I learn it all at once then start to code with it? Any help would be greatly appreciated.
Hi,

Welcome to the Forum :+D

Perhaps best if you show us code you are having trouble with. OOP is a larger subject than what one might think. It is actually a whole paradigm of it's own, one of 4 mentioned by Scott Meyers: C programming ; Object Oriented ; Template C++ ; The Standard Template Library. I think there should be a fifth: Template Meta Programming - quite different to "ordinary" template code.

Learning a little bit, then writing code for it is definitely a good way to go. Don't try to read about lots of different concepts, then try to combine code for them all at once, that's when it could become too hard and confusing.

Which book are you learning from? There are many bad / good books out there. I put a link below for recommended books.

Also google for tutorials, start with the one on this site. There is reference material here too. Here are some good sites:

http://en.cppreference.com/w/cpp
http://en.cppreference.com/w/cpp/links
http://en.cppreference.com/w/cpp/links/libs
https://isocpp.org/
https://isocpp.org/faq
http://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines

https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list

This is personal opinion: I am not a fan of Code::Blocks, mainly because it doesn't seem to background compilation (shows errors as one types in code), and it doesn't have any form of code version system.

There is a very good version system called GIT which can be integrated into many IDE's.

In terms of IDE's , I use Eclipse which works with plugins, of which there are about 1800. Want to program in some language or script? Install the plugin for it. It is not just languages, there are a heap of other things too.

But there are lots of other options too. On Windows there is a community edition of Visual Studio. There are many cross platform IDE's too. There is also QtCreator which comes with the Qt framework - with that one can do all kinds of things.

If you are really keen, you could install Linux on a spare HD partition - Ubuntu is fairly easy for those new to Linux.

Good Luck !!
Thanks for the response, I am learning from the "SamsTeachYourself C++ eighth edition". I will try out eclipse. I will check out those sources for more help. I have read that many people wish they learned code early on, so I will keep chugging along, and hopefully Ill get it soon enough!
No worries, pleased to help :+)

There are quite a few very experienced, guru members on this site, just keep that in mind.

It's good you started coding already, it means you will have quite an advantage once you get to University, even though an introductory course might be in another language like Python or Java say. Once you have some experience in 1 language, it's much easier to pick up another. Five years is a good amount of time to get a really good grasp of 2 languages.

I strongly suggest that you post code here, even if it works and you are happy with it. There are people here that can pull code to bits, criticise every little thing, so you could really learn a lot from that. There is a lot of bad code on the Internet and in books, and the C++ language is evolving all the time, and there are alternative ways of doing things, so might as well learn as much as possible about the best way to do things from the experts here. It's not only the code, but how one compiles it. There are other things like idioms and design patterns.

With classes, the simple idea is that they have some data members (private: access), and some functions that use that data.

Some of these functions are public:, they form the class' interface, the interface can exist in a base class too. Functions can be protected: or private: too, meaning they can be used only by derived classes, or only by the class itself.

Classes can also have overloaded operators, meaning for example one can provide ones own function to carry out the + operation for your object. So if you has a Point class, you can provide operators to add, subtract, scalar multiply, cross and dot products. Another example is the std::string class, one of the operators it has is the operator+ so one can concatenate (join together) strings with it.



Finally there are sites like Project Euler which has some 500 coding challenges, starting out easy and getting harder. Usually brute force is not the way, there will be some method of making life easier, even for the very first problem - there is a formula to use, one you may not have thought of. So this could be an excellent learning resource, get that thinking cap on, set brain mode to clever with lateral thinking.

https://projecteuler.net/about
https://projecteuler.net/archives
Topic archived. No new replies allowed.