转:从VC++到GCC移植:谈两者语法差异

来源:csdn 作者:许式伟 2007-12-01 出处:pcdog.com

下一页 1 2 3 

  作者:许式伟 (版权声明)

  类型引用

以下是引用片段:
  template 
  class Foo
  {
  typedef T::SomeType SomeType;
  };

  这段代码在VC++中一点问题也没有,但是GCC并不允许,因为它不知道T::SomeType是什么。你需要改为:

以下是引用片段:
  template 
  class Foo
  {
  typedef typename T::SomeType SomeType;
  };

  通过typename T::SomeType告诉GCC,SomeType是一个类型名,而不是其他东西。

  当然,这种情况不只是出现在typedef中。例如:

以下是引用片段:
  template 
  void visit(const Container& cont)
  {
  for (Container::const_iterator it = cont.begin(); it != cont.end(); ++it)
  ...
  }

  这里的Container::const_iterator同样需要改为typename Container::const_iterator。



下一页 1 2 3 
上一篇:关于MFC内部结构实用的一点看法
下一篇:VC++开发的应用技巧三则放送