【发布时间】:2015-03-06 14:14:29
【问题描述】:
我希望能够在调用结构时直接从结构返回一个值,而不是通过其成员函数访问我想要的内容。这可能吗?
例如:
#include <iostream>
using namespace std;
enum FACE { NORTH, SOUTH, EAST, WEST };
struct Direction {
FACE face;
};
int main(){
Direction dir;
dir.face = EAST;
cout << dir; // I want this to print EAST instead of having to do dir.face
}
【问题讨论】:
-
您可以提供
ostream& operator<<(ostream& , FACE)