Friday, November 19, 2010


The following program does not compile:

#include <vector>
class MyClass
{ };

int main() {
  ::MyClass myObject;
  std::vector<::MyClass> myVectorOfMyClass;
  return 0;

For it to compile, you have to add a space between '<' and ':'. "<:" is the digraph for '[', and this confuses the compiler. The Sun Compiler has a switch to enable it to tolerate the sytax. Reference: C++ Templates by David Vandevoorde and Nicolai M. Josuttis. Addison-Wesley, 2003, p 206.

No comments:

Post a Comment