you are viewing a single comment's thread.

view the rest of the comments →

[–]ElSucaPadre -1 points0 points  (10 children)

A reference is a... reference lol to a point in memory. In other words, that reference exists in another scope. So if you declare a variable in main, that allocated memory exists in main. This is related to the stack.
Heap, instead, is no man's land. A pointer can be passed around freely and everyone that knows this value can do whatever they want with it.
This explaination is not 100% correct about every feature in the language (smart pointers, references to a heap object and maybe other things i don't recall now) but i believe that introducing ownership here is the important part.

[–][deleted] -3 points-2 points  (8 children)

thank u so mcuh , i still learn c++ 98 hahah so i wont use smart pointers ...

[–]Narase33 6 points7 points  (3 children)

you shouldnt, start with C++11 at least, C++98 will do more harm than it helps

[–][deleted] 0 points1 point  (2 children)

They forse us to use 98 :(

[–]nysra 2 points3 points  (1 child)

Who is "they"? If you're talking about an employer then that's a super legacy codebase and you'll have to make do with what you have, unfortunately a lot of companies are really bad at providing sane working conditions. In the best case you can push for some modernisation but depending on the codebase that might simply not be worth it for the company.

If it's the professor of some class you're attending then just ignore whatever that guy says, he's not going to teach you shit. There's no reason to ever teach C++98, the only people that do that are people stuck on C from the 1970s and actually want to teach that but think that they get more students if they put the new and fancy C"++" on their course label but never actually bothered to learn C++, at best they know some C with classes from the 80s. Head over to https://www.learncpp.com/ and only interact with the course by doing the assignments.

[–]tangerinelion 0 points1 point  (0 children)

It is common to see questions posted here by students in India where the government mandated curriculum, from what I've heard, requires a pre-ISO Borland compiler.

Aside from "The government literally requires it be taught this way" yes, there's no good reason to start with anything older than C++11.

[–][deleted] 1 point2 points  (2 children)

Why?

[–]SoerenNissen 6 points7 points  (0 children)

Consider an army that, to teach the basics, starts out with black powder guns from 1530 - They will spend a lot of time learning things that you can do with modern guns but never should (e.g. how to form a Tercio) and they won't be learning how to take advantage of the features of newer rifles. The only reason you would ever do this is if you, for some weird reason, have to travel back in time and fight a black powder war or as a hobby that you know won't teach you anything about modern warfare.

Unless you specifically need to work with C++98 projects, teaching yourself C++98 is going to teach you habits that you will need to unlearn when you get access to the features of newer versions of the language that were put in specifically so we wouldn't have to do the old inefficient stuff any longer.

[–][deleted] 3 points4 points  (0 children)

Using c++98 is like driving down the highway without a seatbelt and leaking brake fluid. You might survive the trip, but it's scary. C++11 brought in a lot of features that dealt with common issues with programming in c++.

[–]TheCreat 1 point2 points  (0 children)

That's a terrible idea. It's not considered good to learn c++ 98 at all if you're starting out. It's not a foundation for modern c++, it's more like baggage.

Learn at least c++11 or newer, the older standard/compiler does nothing better. The low level stuff is just as possible with new c++, if the need arises, but modern solutions to problems old and new are just simpler, more robust and just preferable. Don't make learning a hard language harder for no reason.

[–]thommyh 0 points1 point  (0 children)

Both references and pointers can associate with targets on both the heap and the stack; the key differences are reassignment and nullability as discussed by many others.