← Return to topic

Pitfalls to avoid with learning C++ coming from C.

comfred · 6 Sep 2026 at 12:29 · permalink

Hello, I am wanting to learn C++, I'm abit stuck around how to go about learning it. I have some background in C, I have 1 I think I can say largish scale project that I have made with it, so im semi confident. Defo dont know everything about it through. (actually editing this I didn't use std so I really don't know much about it, through I understand some of it)

From there I have background in languages like python, rust, javascript, etc. I tend to learn best by just doing and google syntax as I go however C++ has alot of ways todo stuff, some some stuff I havent seen before and you can just code straght C as c++ and have it work. Because of this I am wanting to learn to write C++ well and not end up writing terrible C++ code that some where C and C++ frangensten.

Mostly part that worries me is around classes and sub classes as its an area I haven't touched much, I did abit of c# (unity) when I was new to programming so i know rough idea but I was so new I dont know alot. I also have used rust with structs and impls but its not really same thing.

I am also worried about areas I might miss and do incorrectly (messy), for example using pointers instead of references as there appears to be many ways todo things unlike most lanauages I've used before.

I suppose I am asking for a way to learn good C++ programming pactaise, like a list of things to avoid or even better away to spot how to avoid them? I'd really prefer not to read tons but if its really a must do to get best results I can.

I get the feeling some amount of this is being over paranoid that isn't justifed, I tend to find it hard to get an idea with this sort of stuff as words dont mean alot compared to doing I've found lol. (could go here about how I should probs read more of other peoples code but thats another ramble lol)

comfred · 6 Sep 2026 at 12:29 · permalink

I get the feeling after having written I could have said the same thing in like 3 sentences.

wuyanlong · 6 Sep 2026 at 12:38 · permalink

your instinct about not writing c-frankenstein is spot on, that's the biggest trap

the single best thing you can do is pretend c doesn't exist while you're learning. use \std::vector\ instead of arrays, \std::string\ instead of char\*, references instead of pointers where you can, range-based for loops instead of index loops. if you catch yourself reaching for malloc or raw new, stop and think if there's a container or smart pointer that does it better

for classes, just start simple. make a small project where you model something real, like a library system or a game inventory, and you'll naturally figure out when inheritance makes sense vs when you're overcomplicating it. it clicks faster through doing than reading

the fact you're worried about this at all means you'll probably write better c++ than 90% of beginners who just bash out c with cout

garyosavan · 6 Sep 2026 at 12:39 · permalink

We all do it 😆

comfred · 6 Sep 2026 at 12:46 · permalink

Ok thank you for the advice.

Going to be a fun one trying to get a project that I find intressting enough to learn C++ for some reason lol. I might just have to push myself todo it for once lol. Problem with learning rust first is it does everything well enough. Through I do wanna learn C++ even ignorng all advantages around how ofion others use it, rust can just be very annoying somtimes.

agustinpicho · 6 Sep 2026 at 13:11 · permalink

Great question, thanks for posting this.

youngmichael · 6 Sep 2026 at 13:34 · permalink

There are books for this…

ziguadongnange · 6 Sep 2026 at 13:47 · permalink
I have 1 I think I can say largish scale project that I have made with it,
What is largish to you? For us professional folks, "large" starts somewhere around 100000 lines of code, and it's rather unusual to have a project of that size without knowing the language very well.
Mostly part that worries me is around classes and sub classes as its an area I haven't touched much
Classes are not really necessary, but are a solution to problems that come up in large C code bases all the time. For example: - do you have namespace pollution, where all your C functions are named _ or _ to avoid collisions with similar functions while taking a pointer to that struct as first argument? Just make that struct a class and put the functions as members in there, and they belong naturally to the struct data. - do you have an issue with lifetime management? Do you sometimes worry whether a complex struct is actually initialised properly? C++ constructors to the rescue, a proper constructor guarantees that afterwards the object is fully initialised.
or example using pointers instead of references as there appears to be many ways todo things unlike most lanauages I've used before.
Yeah, that's C++ unfortunately. 20 layers of ways to do stuff. In modern C++, you should mostly get away without ever having to declare a raw pointer unless you want to specifically use C-style low level memory stuff. Whenenver you want to pass by reference, just use a reference instead. Whenever you inject a dependency somewhere, give them a shared_ptr instead. Whenever you need optional data, use std::optional instead.
I'd really prefer not to read tons
Then C++ is the wrong language I fear. C++ is gigantic, full of legacy stuff and the best practices shift every few years, but to understand legacy code you still need to know a ton of weirdness. If you want an ecosystem with less surface area, stick to C or Go.
ken7705 · 6 Sep 2026 at 13:51 · permalink

Use string_view instead of string&

alewkaeee · 6 Sep 2026 at 14:20 · permalink

So I've been teaching myself C++ for about 2 years now. These are things I've found useful.

Use clang-tidy and a restrictive set of compiler flags. This is a github link to Jason Turners config. It makes for a great starting point. From your post, I suspect you'll find modifying it as you go along easy.

For compiler flags, at a minimum, I would suggest these. They are what I started with and they served me well. I have a much larger list I use now that I could share if you're interested. They work on clang and gcc. If you use mscv Google their version of them. Msvc versions exist for all of these but I don't use windows and don't know them.

-Wall, -Wextra, -Werror.-Wpedantic, -Wconversion, -Wshadow, -Wnon-virtual-dtor, -Wold-style-cast

There are a couple more for debug builds but I'm assuming you already know those from your time with C. I think they are the same.

You mentioned concerns over using reference instead of pointers and clang-tidy will help. One of its performance checks will tell you if you are passing by value when you could be passing by const reference and the core-guidelines checks should get a lot of unnecessary pointer usage. You might need to do some research and config modifications but just the core guidelines checks will do a lot to keep you writing C++ instead of C.

Do not ignore the warnings. Learn to build without warnings and your life will be easier.

Never alias the standard library into your code base.

using namespace std; // don't do this you can Google why.

There are a lot of implicit conversations in C++. It's one of the only things I dislike about the language.

Use modern C++23 whenever possible. In my short time writing C++ I've never written new, delete, malloc or free. Smart pointers and good RAII along with modern C++ make those things obsolete for new learners that aren't working in production code. I qualify that a lot because I mean obsolete for a learner. Not obsolete by any reasonable production code standard. You shouldn't use them. There are better modern alternatives that will reduce memory bugs.

Some things to Google and lean towards as you're looking up syntax. These headers are the ones I use the most. You can read more about them on cppreference.com, which is the best documentation website.

array, vector, unordered_map, print, ranges, algorithm, iterator, iostream.

LEMONTCH9 · 6 Sep 2026 at 21:14 · permalink

Think of classes as a form of composition. For example,

typedef struct {
ListNode next, prev;
} ListNode;

typedef struct {
ListNode node;
int id;
char name[40];
int salary;
time_t hire_date;
} Employee;

const Employee* next_employee = current_employee.node.next;

ListNode ListNode_next(ListNode node) { return node->next; }

is apart from naming the same as:

class ListNode {
public:
class ListNode next, prev;

ListNode* next() { return next; }
};

class Employee: public ListNode {
public:
int id;
char name[40];
int salary;
time_t hire_date;
};

const Employee* next_employee = current_employee.next;

C++ just then gives you more tools, checks, validation. In part it makes the code more concise, in part it helps with namespace hygiene, which is the practice of not having everything in a global namespace and embedding type names in functions to differentiate what they operate on.

comfred · 7 Sep 2026 at 02:08 · permalink

Completely fair criticism on the size, it's honestly a really silly way to put it. The project is around 4.5k lines of code, so pretty small on that scale. I guess I meant more not really a starter project, but a bit more complex one? Idk either way, large wasn't really a good way to put it in the slightest.

On your note about lifetime management, it is probably the worst project I could have picked around learning most the life time management stuff if i wanted to go from C to c++ as the closest I got around using libc was coding my own allocator and basic string handlers. I know most of it in theory but haven't used much in practise, Most of the languages I have used before it was handled before for me. Doesn't really make me not want to use it tho just a fun feature of the langauge. Classes make sense putting it that way, I suppoes thats really what it boils down to.

Haha yeah I've honestly spoiled myself with writing mostly in really nice langauges and frameworks so alot of stuff has been fairly fine so far. That makes sense around that it does remind me abit like rust. I mean I had same thing with choosing sveltekit over react where I didn't need to learn alot.

I should have been a lot more clear around what read means. I mean that alot of the time people say to read like these massive books for learning languages and It really is just not how I learn best. I kinda learn best by learning by doing and seeing what is best. I mean its not like I can't. Like I read the rust book to learn rust and thought it was great. But i just find it alot more intressting and motivating to learn through doing. I don't really think surface area is a problem for me? I mean I dont wanna spend the next 5 years larning C++ or something like that if its in that respect.

comfred · 7 Sep 2026 at 02:24 · permalink

Very intressting and smart way to go about this. Implicit converstions remind me alot of higher level lanaguages was always a problem I had with them in the respect they could convert between things without telling you. Weirdly enough, why I really liked when languages made you define the type.

Thanks for comment I'll give your advice a try.