我正在处理一些代码,并且我遇到了一些错误,这些错误与定义/声明和期望我的类名称的类型说明符有关吗?
我想知道是否有人可以简单地向我解释我出错的地方以及如何解决这些问题?
我已经注释掉了每一行的错误,Boot and Shoe和Footwear是头文件中的类#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;
}
blockquote {
background: #f9f9f9;
border-left: 10px solid #ccc;
margin: 1.5em 10px;
padding: 0.5em 10px;
quotes: "\201C""\201D""\2018""\2019";
}
答案 0 :(得分:1)
使用:std::vector
这可能会清除所有警告。您已经包含但仍需要在std
命名空间前加上前缀。
在for循环中,您必须声明for(int i = 0....)
您可能希望使用unsigned int
,因为collection.size()
永远不应该是< 0
。