fin*_*oop 3 c++ stl g++ standard-library
我试图使用g ++ 4.2.1编译以下代码并收到以下错误
码:
#include <iostream>
#include <queue>
using namespace std;
int main (int argc, char * const argv[])
{
queue<int> myqueue();
for(int i = 0; i < 10; i++)
myqueue.push(i);
cout << myqueue.size();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
错误:
main.cpp: In function ‘int main(int, char* const*)’:
main.cpp:10: error: request for member ‘push’ in ‘myqueue’, which is of non-class type ‘std::queue<int, std::deque<int, std::allocator<int> > > ()()’
main.cpp:12: error: request for member ‘size’ in ‘myqueue’, which is of non-class type ‘std::queue<int, std::deque<int, std::allocator<int> > > ()()’
Run Code Online (Sandbox Code Playgroud)
任何想法为什么?我在Eclipse,X-Code和终端中尝试过.
eph*_*ent 10
有什么区别
List x;和List x();?一个很大的区别!
假设这
List是某个类的名称.然后函数f()声明一个List名为的本地对象x:Run Code Online (Sandbox Code Playgroud)void f() { List x; // Local object named x (of class List) ... }但是函数
g()声明了一个函数x(),它返回一个List:Run Code Online (Sandbox Code Playgroud)void g() { List x(); // Function named x (that returns a List) ... }
替换queue<int> myqueue();为queue<int> myqueue;,你会没事的.