C++ 这个typedef语法是如何工作的。。? #包括 #包括 类型定义ostream&(*T)(ostream&,int); 阶级基础 { 不好玩; int-var; 公众: 基本(T func,int arg):fun(func),var(arg) {}; friend ostream&运营商

C++ 这个typedef语法是如何工作的。。? #包括 #包括 类型定义ostream&(*T)(ostream&,int); 阶级基础 { 不好玩; int-var; 公众: 基本(T func,int arg):fun(func),var(arg) {}; friend ostream&运营商,c++,typedef,ostream,C++,Typedef,Ostream,这将创建名为T的typedef,它是指向具有以下属性的函数的指针: 返回对ostream 按以下顺序接受两个参数: 对ostream intvalue oStase,假设它是“代码> STD::OsFoes/CODE >,它本身就是一个代码< TyPufF,它在C++标准库中找到,它被定义为: typedef ostream& (*T)(ostream& , int); 这是一个包含两个内容的类:(1)指向上述函数的指针;(2)整数。构造函数(3)允许类的用户使用函

这将创建名为
T
typedef
,它是指向具有以下属性的函数的指针:

  • 返回对
    ostream
  • 按以下顺序接受两个参数:
    • ostream
    • int
      value

<代码> oStase,假设它是“代码> STD::OsFoes/CODE >,它本身就是一个代码< TyPufF,它在C++标准库中找到,它被定义为:

typedef ostream& (*T)(ostream& , int);
这是一个包含两个内容的类:(1)指向上述函数的指针;(2)整数。构造函数(3)允许类的用户使用函数指针和整数对其进行实例化

友元函数声明(4)重载左位移位运算符

这将创建名为
T
typedef
,它是指向具有以下属性的函数的指针:

  • 返回对
    ostream
  • 按以下顺序接受两个参数:
    • ostream
    • int
      value

<代码> oStase,假设它是“代码> STD::OsFoes/CODE >,它本身就是一个代码< TyPufF,它在C++标准库中找到,它被定义为:

typedef ostream& (*T)(ostream& , int);
这是一个包含两个内容的类:(1)指向上述函数的指针;(2)整数。构造函数(3)允许类的用户使用函数指针和整数对其进行实例化


友元函数声明(4)重载左位移位运算符
iostream.h
早已过时。请改用
iostream
并在其中的所有内容前面加上
std::
。当我这样做时,
conio.h
也非常陈旧,不推荐使用。规范中甚至没有提到这两种类型。无论如何,
std::ostream
s的类型td::cout
。如果有帮助的话,用任何其他类型替换它。
iostream.h
早就不存在了。改用
iostream
并在其中的所有内容前面加上
std:
。当我这样做的时候,
conio.h
也非常旧,而且不推荐使用。规范中甚至没有提到这两种类型。总之,
std::ostream
是t
std::cout
的类型。如果有帮助,用任何其他类型替换它。为了避免混淆,
operatornice回答:
return Base(odisp,i);
将正确调用
Base
的构造函数和
odisp
函数(通过函数指针获取)。(我不明白为什么
Base
被称为“Base”。)为了避免混淆,
operatornice回答,除了结尾的一个小错误:
returnbase(odisp,I);
将是对
Base
的构造函数的正确调用,使用
odisp
函数(通过函数指针)。(我不明白为什么
Base
被称为“Base”。)
typedef ostream& (*T)(ostream& , int);
namespace std {
    typedef basic_ostream<char> ostream;
}
class Base
{
    T fun; // (1)
    int var; // (2)
public:
    Base(T func, int arg): fun(func) , var(arg) {}; // (3)

    friend ostream& operator<<(ostream& o, Base& obj) // (4)
    {
        return obj.fun(o, obj.var);
    }
};
ostream& odisp(ostream& o, int i);
{
    o << "i=" << i << endl;
    return o;
}
Base disp(int i)
{
    return base(odisp, i)
};