我有一个简单的C++结构,可以构建一个
std::队列
使用主电源的argv。
然后,它提供了一种方法
::下一页
在将当前值从队列中弹出之前返回它。
如果我将此方法作为函数的参数调用,它将把参数还原为:
wut(cunext(),cunexts());
以[1,2]作为main上的条目,它给了我以下输出:
第一个参数是2
第二个参数为1
这是我对std::queue的误解吗?
有罪代码:
#include <iostream>
#include <queue>
using namespace std;
struct Args
{
public:
typedef std::string Arg;
Args(int argc, char* argv[]);
Arg current() const;
Arg cunext();
private:
std::queue<std::string> q_args; ///< Queue of arguments as std::string objects.
};
Args::Args(int argc, char* argv[]):
q_args()
{
for(int i=1; i<argc; i++) // build queue for arguments
{
q_args.push(*(++argv)); // skip first argument (as for path)
}
};
inline Args::Arg Args::current() const
{
return q_args.front();
};
inline Args::Arg Args::cunext()
{
Arg ret = current();
q_args.pop();
return ret;
};
void wut(std::string bad, std::string good)
{
cout << "first param is " << bad << endl;
cout << "second param is " << good << endl;
}
int main(int argc, char* argv[])
{
Args args(argc, argv);
wut(args.cunext(),args.cunext());
return 0;
}