小编Muh*_*zan的帖子

打印std :: array

因此,在使用std :: array时,我想要一种简单的方法来打印出数组的所有元素,并尝试以下方法:

using namespace std;

template <class T, int N>
ostream& operator<<(ostream& o, const array<T, N>& arr)
{
    copy(arr.cbegin(), arr.cend(), ostream_iterator<T>(o, " "));
    return o;
}

int main()
{
    array<int, 3> arr {1, 2, 3};
    cout << arr;
}
Run Code Online (Sandbox Code Playgroud)

但是,每当我尝试运行它时,我都会收到以下错误:

test.cpp: In function 'int main()':
test.cpp:21:10: error: cannot bind 'std::ostream {aka std::basic_ostream<char>}' lvalue to 'std::basic_ostream<char>&&'
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/ostream:581:5: error:   initializing argument 1 of 'std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&&, const _Tp&) [with _CharT = char, _Traits = std::char_traits<char>, _Tp = std::array<int, 3u>]'
Run Code Online (Sandbox Code Playgroud)

关于这个错误意味着什么,以及我将如何修复它的任何想法? …

c++ arrays c++11

12
推荐指数
1
解决办法
5129
查看次数

为什么第一类函数的类型不能包含byrefs?

例如,以下是不允许的,我不知道为什么:

> let f () = 
    let f2 (a : byref<int>) =
        ()
    let mutable a = 0
    f2 &a;;
Run Code Online (Sandbox Code Playgroud)

我的猜测是,byref可能是对堆栈变量的可变引用,如果f2决定将其存储在某个地方,它可能会超出范围.或者是别的什么?

f#

6
推荐指数
1
解决办法
160
查看次数

标签 统计

arrays ×1

c++ ×1

c++11 ×1

f# ×1