我正在尝试使用g ++ 4.2.1编译以下代码,并收到以下错误信息。
代码:
错误:
任何想法是为什么?我尝试过在Eclipse、X-Code和终端中运行。
代码:
#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;
}
错误:
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> > > ()()’
任何想法是为什么?我尝试过在Eclipse、X-Code和终端中运行。
Foo bar;
构造函数使用Foo::Foo()
。Foo bar(a,b,c);
构造函数使用Foo::Foo(a,b,c)
。new Foo;
和new Foo()
都可以构造一个Foo
,但意义略有不同。是的,这很不一致和可怕。这就是 C++ :) 这就是为什么有些人更喜欢写Foo bar = Foo();
和Foo bar = Foo(a,b,c);
但我也不太喜欢那样... - ephemientFoo bar()
并没有构造任何东西。相反,它是一个声明:“在这个作用域中,bar
是一个不带参数并返回Foo
的函数”。当然,仅有声明而没有定义,你不能对bar
做任何有用的事情... - ephemient