gpt4 book ai didi

c++ - gcc模板错误

转载 作者:行者123 更新时间:2023-11-28 08:28:10 25 4
gpt4 key购买 nike

为什么在这段代码的第一行:

template <typename VectorType>
std::string repr_vector_dynamic(const VectorType* vect)
{
std::stringstream strs;
strs << "(";
for (int i = 0; i < vect->size(); ++i) {
if (0 != i) {
strs << ", ";
}
strs << (*vect)[i];
}
strs << ")";
return strs.str();
}

我总是在第一行遇到这些错误:(MinGW gcc 4.5)

expected ';' before 'template'

expected primary-expression before 'template'

谢谢

稍后编辑:这是我从 eclipse 获得的命令行/日志:

g++ -II:\proj\bp\PyCML -IC:\PF\Python26\include -II:\proj\bp/include -O3 -Wall -c -fmessage-length=0 -oPyCML\cml.o ..\PyCML\cml.cpp
In file included from I:\proj\bp/include/boost/python/object/make_instance.hpp:9:0,
from I:\proj\bp/include/boost/python/object/make_ptr_instance.hpp:8,
from I:\proj\bp/include/boost/python/to_python_indirect.hpp:11,
from I:\proj\bp/include/boost/python/converter/arg_to_python.hpp:10,
from I:\proj\bp/include/boost/python/call.hpp:15,
from I:\proj\bp/include/boost/python/object_core.hpp:14,
from I:\proj\bp/include/boost/python/args.hpp:25,
from I:\proj\bp/include/boost/python.hpp:11,
from ..\PyCML\cml.cpp:11:
I:\proj\bp/include/boost/python/object/instance.hpp:14:36: warning: type attributes ignored after type is already defined
In file included from ..\PyCML\cml.cpp:28:0:
I:\proj\bp\PyCML/PyCMl/vector.h: In function 'void init_module_PyCML()':
I:\proj\bp\PyCML/PyCMl/vector.h:22:1: error: expected primary-expression before 'template'
I:\proj\bp\PyCML/PyCMl/vector.h:22:1: error: expected ';' before 'template'
..\PyCML\cml.cpp:58:1: error: expected '}' at end of input

最佳答案

正如其他人所建议的那样,它是 template 之前发生的事情缺少 ; 的声明.

看看编译器看到了什么,因此:

g++ -E <yourfile>.cpp | less

关于c++ - gcc模板错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3221422/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com