When are volatile copy constructors safe?

I have a situation where I had to go back and assign copy constructors to follow the rule of 5 or whatever you call it. When assigning a copy constructor to one of my classes that had a node pointer in a list, the only combination of the copy constructor type that worked without error was one that was like classNAme( volatile &className).
Last edited on
I would guess that you have undefined behavior somewhere in your program and this shifts the problem a bit. volatile is normally not necessary.
You can always add cv-qualifiers. volatile follows the same rules as const as to when it can be added implicitly (always) and removed (only explicitly and very carefully with const_cast). Yes, you can cast away volatile using const_cast.

Maybe classNAme( volatile &className) implies that the copy-constructor was accepting a volatile reference (though this snippet wouldn't compile.) Why this is required is anyone's guess.

volatile tends to be misunderstood, and occasionally misused. It's rarely necessary except when working at a hardware or near-hardware level. To potentially clear a misconception, volatile has absolutely nothing to do with concurrency, and if you're using it in that context you're almost certainly doing something wrong.

Your terminology is a bit confusing. (How do you assign a copy constructor? What is a combination of a copy constructor?) Can you provide a code example?
Last edited on
Topic archived. No new replies allowed.