我正在尝试将以下c ++代码从Windows交叉编译到arm-linux。为此,我将gcc arm-linux-gnueabihf工具链与基于eclipse的ARM-DS5一起使用。
#include<iostream>
#include <boost/circular_buffer.hpp>
// Create a circular buffer with a capacity for 3 integers.
boost::circular_buffer<int> cb(3);
// Insert threee elements into the buffer.
cb.push_back(1);
cb.push_back(2);
cb.push_back(3);
int a = cb[0]; // a == 1
int b = cb[1]; // b == 2
int c = cb[2]; // c == 3
{
cout << "cb["<<i<<"] =" << cb[i] << endl;for (int i = 0; i<3; i++)
}
// The buffer is full now, so pushing subsequent
// elements will overwrite the front-most elements.
cb.push_back(4);// Overwrite 1 with 4.
cb.push_back(5);// Overwrite 2 with 5.
// The buffer now contains 3, 4 and 5.
a = cb[0];// a == 3
b = cb[1];// b == 4
c = cb[2];// c == 5
// Elements can be popped from either the front or the back.
cb.pop_back();// 5 is removed.
cb.pop_front();// 3 is removed.
// Leaving only one element with value = 4.
int d = cb[0]; // d == 4
[包括了头文件的必需路径后,我构建了项目,并且遇到以下错误
11:36:12 **** Incremental Build of configuration Debug for project Circular_buffer ****
Info: Internal Builder is used for build
arm-linux-gnueabihf-g++.exe "-IE:\\programs\\boost_1_62_0\\boost_1_62_0" -O0 -g -Wall -c -fmessage-length=0 -o circular.o "..\\circular.cpp"
..\circular.cpp:13:1: error: 'cb' does not name a type
cb.push_back(1);
^~
..\circular.cpp:14:1: error: 'cb' does not name a type
cb.push_back(2);
^~
..\circular.cpp:15:1: error: 'cb' does not name a type
cb.push_back(3);
^~
..\circular.cpp:20:1: error: expected unqualified-id before 'for'
for (int i = 0; i<3; i++)
^~~
..\circular.cpp:20:17: error: 'i' does not name a type
for (int i = 0; i<3; i++)
^
..\circular.cpp:20:22: error: 'i' does not name a type
for (int i = 0; i<3; i++)
^
..\circular.cpp:29:1: error: 'cb' does not name a type
cb.push_back(4);// Overwrite 1 with 4.
^~
..\circular.cpp:30:1: error: 'cb' does not name a type
cb.push_back(5);// Overwrite 2 with 5.
^~
..\circular.cpp:33:1: error: 'a' does not name a type
a = cb[0];// a == 3
^
..\circular.cpp:34:1: error: 'b' does not name a type
b = cb[1];// b == 4
^
..\circular.cpp:35:1: error: 'c' does not name a type
c = cb[2];// c == 5
^
..\circular.cpp:38:1: error: 'cb' does not name a type
cb.pop_back();// 5 is removed.
^~
..\circular.cpp:39:1: error: 'cb' does not name a type
cb.pop_front();// 3 is removed.
^~
11:36:14 Build Finished (took 1s.893ms)
我正在使用不需要构建的仅标头的库,所以为什么会收到报告的错误?
这是我的错误,我匆忙复制了代码,甚至没有注意到没有主体。将主体添加到代码中解决了该问题。