我正在编写一些代码,但遇到了一些与定义/声明和期望类名所在的类型说明符有关的错误?
我想知道是否有人可以简单地向我解释我哪里出了问题以及如何解决这些问题?
我已经注释掉了每一行的错误,Boot 和 Shoe 以及 Footwear 是头文件 Footwear.h
中的类
#include <iostream>
#include <string>
#include <vector>
#include "typedefs.h"
#include "Footwear.h"
int main(int argc, const char * argv[])
{
vector<Footwear*> collection; // vector and Footwear are undefined
Footwear* f; //f undefined
f = new Boot("Timbaland",10); //expected a type specifier
collection.push_back(f); //collection undefined
f = new Shoe("Brogue",5); //expected a type specifier
collection.push_back(f);
for (i = 0; i < collection.size(); i++) //i undefined
collection[i]>toString(); //toString undefined
return 0;
}
最佳答案
使用:std::vector
这可能会清除所有警告。您已经包括在内,但您仍然需要在 std
前加上前缀命名空间。
在你的 for 循环中,你必须声明 for(int i = 0....)
你可能想使用 unsigned int
自 collection.size()
永远不应该是 < 0
.
关于c++ - 声明/定义和 vector 的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32146005/