lvalue required as left operand of assignment in C++ class

Pages: 12
Thanks to @jonnin for taking my defense while I was away and that's why I'm not going to justify my posts above anymore.

@seeplus you know that the naked pointer (C-Style) are source of many errors and bugs in C++ so stop proposing a solution to a beginner by using codes that expose this kind of pointer.

And just to chat, why didn't you use std::move in your move constructor?
@Jonin: thanks for the detail suggestion. And you are right about raw pointers and their extensive use still in some libraries. I am dealing with one such C++ codebase that has an overwhelming use of raw pointers.....it's hell and pain (on a lighter note) but it's exciting ;)....
Last edited on
so stop proposing a solution to a beginner by using codes that expose this kind of pointer.


The OP wanted to practice pointers - hence didn't use managed pointers. Many courses/resources teach new/delete before teaching managed pointers (if they do this at all). Taking this reasoning further, why use (managed) pointers at all in this case and just use say std::vector?

Being able to use new/delete etc properly in a class I would consider is of some importance - as it is common and likely to be encountered. There is less reason to use outside of a class - as that is where problems are more likely to be encountered without using managed pointers.

Really, with modern C++ you don't need to know about pointers/memory etc until you start to study linked structures (list etc). But a lot of courses still teach this stuff early on when IMO it shouldn't be.
I struggle with that one. I feel that my background, which taught pointers right off (well, fairly early, before OOP was even mentioned) as just another thing that you had to master if you want to write code, has served me well. It got it out of the way and in the back of my mind so that when we hit lists and trees, I didn't have to think about the pointer parts since I already understood that. But being taught this early creates a hammer and nail problem for some students: you handed them the pointer hammer and everything looks like a nail for a while -- they will use the darn things everywhere when none at all were needed. I don't know when the best time for exposure would be, maybe it depends on the individual more than the info. Early or delayed, it seems to cause trouble one way or another. If you delay, students feel overwhelmed because its expected they will snap it up rapidly while the concept is a little weird and takes some time to solidify.
Well when I was taught Pascal way way back, we covered pointers just before we did linked lists and IMO that is the way/order to teach memory management.

For C++, IMO you'd cover the std::containers/iterators/algorithms first, then cover managed pointers and then raw pointers. That way the students get to know the 'C++ way' before they get 'corrupted' with things like pointers etc. IMO, there's still far to much teaching of C++ as C with 'extras'. The 2 languages are different and IMO should be taught as different languages from the beginning.

Just my 2-cents.

[end of rant!]
Last edited on
The problem is at the origin, because at the time of the appearance of C++ in the market, this last one had like name "The C with class", therefore from the one we can understand that it is enough just to know C and to have a notion on the class we are at once C++ developer, or C and C++ have different approaches certainly there are similarities with C++98 or C++03, but since the major update of C++11, it can be said that C++ does not have anything to have with C.

For those who teach the C-style pointer in C++ courses, are just C developers who compile their code using a C++ compiler.

In my courses I first teach smart pointers and then when the students have a good level, that's when I will go into detail to introduce them with C-Style pointers.
Last edited on
@seeplus: thanks for this additional code snippet. It's helpful......


@El Jos, @jonnin, @seeplus
I
You all three know probably far better than me that there is a flaw in teaching C++ in most schools. There are still many many schools which teach "C/C++". And this is wrong on so many levels.... :)


thanks for the very helpful feedback in this post. Probably I will keep bothering you more now often in next posts with new C++ questions as I take on this C++ intensive practice path..... :)
Topic archived. No new replies allowed.
Pages: 12