0

I have a function that display something, where the character positioning can be different. Function looks like this:

void display(std::ostream & stream, std::ios_base & positioning);

However, when I try to call this function like this

display_header(std::cout, std::left);

I get the following error

error: non-const lvalue reference to type 'std::ios_base' cannot bind to a value of unrelated type 'std::ios_base &(std::ios_base &)'

I don't understand why std::cout can be passed just fine, but std::left refuses to do so. Also how is lvalue reference to type 'std::ios_base' different from lvalue reference to type 'std::ios_base' ?

4

1 回答 1

5

像大多数流操纵器一样,std::left它是一个函数,而不是一个变量。 display将需要更改为

void display(std::ostream & stream, std::ios_base &(*positioning)(std::ios_base &));

为了接受left, right, internal, 或任何其他类型的操纵器std::ios_base &(std::ios_base &)

于 2017-06-27T16:03:33.750 回答