我有一个显示某些东西的功能,其中字符定位可以不同。函数如下所示:
void display(std::ostream & stream, std::ios_base & positioning);
但是,当我尝试这样调用这个函数时
display_header(std::cout, std::left);
出现以下错误
error: non-const lvalue reference to type 'std::ios_base' cannot bind to a value of unrelated type 'std::ios_base &(std::ios_base &)'
我不明白为什么 std::cout
可以顺利通过,但是 std::left
拒绝这样做。另外,lvalue reference to type 'std::ios_base'
与 lvalue reference to type 'std::ios_base'
有何不同?
最佳答案
最喜欢 stream manipulators , std::left
是函数,不是变量。 display
需要更改为
void display(std::ostream & stream, std::ios_base &(*positioning)(std::ios_base &));
为了接受 left
、right
、internal
或 std::ios_base &( std::ios_base &)
.
关于c++ - 将 std::left 作为参数传递,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44784872/