gpt4 book ai didi

c++ - 函数外的 Ublas vector 初始化

转载 作者:行者123 更新时间:2023-11-28 07:39:22 26 4
gpt4 key购买 nike

我想将特定的 boost ublas vector 声明为全局变量。问题是函数外的声明总是会导致错误。

这是一个具体的例子:

以下代码将给出多个错误:( error C2143: syntax error : missing ';' before '<<=' error C4430: missing type specifier - int assumed. error C2371: 'test' : redefinition; different basic types )

#include <boost/numeric/ublas/matrix.hpp>
#include <boost/numeric/ublas/io.hpp>
#include <boost/numeric/ublas/assignment.hpp>
using namespace boost::numeric::ublas;

vector<int> test(3);
test <<= 1,2,3;

void main () {
std::cout << test << std::endl;
}

然而,将声明移至主程序是可行的

#include <boost/numeric/ublas/matrix.hpp>
#include <boost/numeric/ublas/io.hpp>
#include <boost/numeric/ublas/assignment.hpp>
using namespace boost::numeric::ublas;

vector<int> test(3);

void main () {
test <<= 1,2,3;
std::cout << test << std::endl;
}

最佳答案

当然会导致错误,因为它是

test.operator <<= (1,2,3);

但是你不能在函数外调用函数。

关于c++ - 函数外的 Ublas vector 初始化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16140775/

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