Erm.. I'm not really getting what you're going onto.. |
Understandable, what I wrote is a mess. What I meant is: how much rules in the standard that lead to run-time bugs you estimate you don't know? A dozen, two dozens, a few hundred, many, few?
I'll just attempt to answer the given example topics |
It wasn't the point really. I don't want to test forum members or some crap like that (even if I find it challenging myself). I am curious about their self-evaluation.
I believe the (derived) virtual operator will be called and executed first, and then the base assignment operator will be called (within the call of the derived operator). |
The derived class will be supplied with default/implicit assignment operator for objects of the derived class type. This assignment operator will not be virtual, but will perform member-wise copy of the fields in the derived class that are not in the base class. Then a static call to the base class assignment operator will be performed.
http://stackoverflow.com/questions/969232/why-does-virtual-assignment-behave-differently-than-other-virtual-functions-of-th
A variety of possible sources which are all the same in the end: the block is exited before the deallocation. This can be because of a break, continue, return, goto, throw or assigning a new value without deleting it first to said pointer. |
True. The cause I really looked for was the exception thing. The code in the body, or one of the allocations can cause exception. If the second allocation triggers exception then the first allocation is a leak.
Given that it can be any member, the worst that can happen is that it is some strange value within the bounds of which it can hold (for standard types, as said, classes and pointers have default values). |
I think so, if I understand you correctly. A member of POD type (kind-of C structure) will then hold arbitrary values in all of its fields.
The virtual base will get default initialized. The derived classes expect initialization with particular parametrized constructor and particular constructor arguments, but they will actually host object that is default-initialized and that may violate their assumptions. Of course, this is all bad design to begin with.
http://www.cplusplus.com/forum/general/33843/
The most common error would be that either the badbit or the failbit are set. |
This is true, but I was shooting at something else. The eof bit is set after reading past the end of the file. So, after reading the last record it is still not set. Then the loop will enter the body one last time, but there is no more data. So, the read will fail, leaving the record structure at its old state. The last record will be therefore processed twice.
Here is an example program:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
|
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
{
ofstream out("test.bin");
for (char i = 'a'; i < 'd'; ++i)
{
out.write(&i, 1);
}
}
{
ifstream in("test.bin");
char i;
while(!in.eof())
{
in.read(&i, 1);
cout << i << endl;
}
}
}
|
The output is:
Regards