![](/img/trans.png)
[英]C++ how to check the signature of a template parameter class at compile time
[英]How to compile template class in C++
我在程序中使用的每個模板類都遇到錯誤。 即使當我從網站復制解決方案並嘗試編譯該解決方案時,也會出現如下錯誤:
set_prac.cc: In function ‘int main()’:
set_prac.cc:10:13: error: ‘it’ does not name a type
for (auto it = std::begin(foo); it!=std::end(foo); ++it)
^
set_prac.cc:10:35: error: expected ‘;’ before ‘it’
for (auto it = std::begin(foo); it!=std::end(foo); ++it)
^
set_prac.cc:10:35: error: ‘it’ was not declared in this scope
set_prac.cc:10:39: error: ‘end’ is not a member of ‘std’
for (auto it = std::begin(foo); it!=std::end(foo); ++it)
...................................................
該程序為http://www.cplusplus.com/reference/iterator/begin/
並且在他們的網站上運行良好。 編譯具有模板的C ++代碼是否需要任何其他功能?
我將其編譯為
g ++ example.cc
正如評論中其他人所指出的那樣,如果您使用的是C ++ 11功能,則由於gcc默認情況下假定c ++ 03,因此您需要包含-std=c++11
。 根據您使用的gcc版本,您可能需要使用-std=c++0x
來代替:
g++ -pedantic -std=c++0x example.cc -o example
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.