注册 登录
编程论坛 C++教室

typedef 和 inline 问题

bclee 发布于 2008-01-25 09:09, 737 次点击
class   screen
{   public   :
        typedef   std::string::size_type   index;
        index   get_cursor()   const;
};
      inline   screen::index   screen::get_cursor()   const
{   return   cursor;
}

为什么会多出红色部分,   在外部的函数定义上指定inline   ,应该也是   inline   +   类名::函数名吧?
2 回复
#2
linsua2008-01-25 09:46
::运算符的优先级最高:screen::index表示screen类里typedef的index;这个typedef只有在类screen才可见。
在类外引用的话就要指明是哪一个类里定义或typedef的。

其实你只要记得XXX::yyy表示的是XXX::里头的xxx就行了。(当然也可能是namespace,不过这个比较好区分)
#3
bclee2008-01-25 10:04
就是说screen::index用法相当于 int 等数据类型 ,只是它规定了这种类型的可见性

inline   (screen::index )  screen::get_cursor()   const     所以应该这样理解吧
         数据 类型       类名    函数

谢谢高人指点!!!
1