我很难让 std::begin() 与动态分配的数组(指针)一起工作,它似乎与堆栈分配的数组一起工作正常。
这有效:
int numbers[100];
// Fill array with numbers
std::sort(std::begin(numbers), std::end(numbers));
Run Code Online (Sandbox Code Playgroud)
这不
int* numbers = new int[10000000];
// Fill array with numbers
std::sort(std::begin(numbers), std::end(numbers));
Run Code Online (Sandbox Code Playgroud)
这是由此产生的错误。
ptests.cpp:120:33: error: no matching function for call to ‘begin(int*&)’
std::sort(std::begin(numbers), std::end(numbers));
^
ptests.cpp:120:33: note: candidates are:
In file included from /usr/include/c++/4.8/utility:74:0,
from /usr/include/c++/4.8/algorithm:60,
from ptests.cpp:1:
/usr/include/c++/4.8/initializer_list:89:5: note: template<class _Tp> constexpr const _Tp* std::begin(std::initializer_list<_Tp>)
begin(initializer_list<_Tp> __ils) noexcept
^
/usr/include/c++/4.8/initializer_list:89:5: note: template argument deduction/substitution failed:
ptests.cpp:120:33: note: mismatched types ‘std::initializer_list<_Tp>’ and ‘int*’
std::sort(std::begin(numbers), std::end(numbers));
^ …Run Code Online (Sandbox Code Playgroud) 我试图了解嵌套如何在SQL服务器中工作,并生成以下代码...
SELECT(*)
FROM
(
SELECT (*)
FROM MPOG_Institutions JOIN AIMS_Patients
ON MPOG_Institutions.MPOG_Institution_ID = AIMS_Patients.MPOG_Institution_ID
) AS a
Run Code Online (Sandbox Code Playgroud)
我目前的理解是内部SELECT,FROM和JOIN语句生成一个结果集,然后在外部SELECT语句的FROM语句中使用该结果集.但是,当运行此代码时,我得到以下语法错误:
Msg 8156, Level 16, State 1, Line 1
The column 'MPOG_Institution_ID' was specified multiple times for 'a'.
Run Code Online (Sandbox Code Playgroud)
我已经读过这些嵌套的结果集需要别名,因此需要"AS a",但随后会出现此错误.任何人都可以帮我理解这里发生了什么?
谢谢!