[Solved] Getting undefined behavior for something that shouldn’t be getting undefined behavior
[ad_1] Your code does have undefined behaviour. But let’s start at the beginning. Sample s1 = new Sample(10); This is what happens in this line: A Sample object is allocated on the heap and the new expression returns a pointer to it, a Sample*. You cannot assign a Sample* to a variable of type Sample. … Read more