Quote:Original post by Xipher
In Big O, if you have a series of instructions where code is not run more then once, its O(1). Even function calls are O(1), and a constructor would fall under that definition, unless the constructor itself contains a loop to do initialzation, it would be O(1). It doesn't matter how many instructions replace the single one you made in code (the casting that is replaced with the constructor if its an object to object cast, either using a copy constructor or one writen by the class author). You can write a program consisting of 100 lines of the same thing, and have another program with 1 loop that runs 100 times, the first is O(1) and the second is O(n). Runtime is NOT what Big-O is about.
No, you are mistaken about what Big O notation means, although it is partly at fault to the wording of the question at hand.
First, in your example, where you give the example of the 100 iteration loop and it's unraveled counterpart, you claim that the two have different complexity, stating that one is O(n) while the other is O(1). The problem is that you never defined what "n" is. In any normal sense of your analysis, "n" would be defined as the amount of objects of which you are iterating over, which here would be 100. Just because one is handled in a loop while the other is not in no way changes the fact that the complexity with respect to the number of elements is O(n).
There is the same exact fault with the original posters question: What is "n." When working with algorithms that operate on an iterator range, "n" is usually the number of elements in the range. Here, however, there is no obvious "n." Assuming pointer types, is "n" the number of bases a type being pointed to has, or perhaps the maximum number of virtual bases it has in series leading to the casted type, or what? Until you define what "n" is, asking to analyze the algorithm with Big O notation is completely meaningless. It would be like telling someone to take the derivative of a function -- your question should be "with respect to what." Until you answer that, you can go no further, since your question is not fully formed.