我在初始化头文件中的结构向量时遇到问题。结构不匹配的C++向量
bins.h
#ifndef BINS_H
#define BINS_H
#include <vector>;
using namespace std;
struct bin
{
//...
bin() {
//...
}
};
class Bins {
public:
Bins();
vector<bin> getBins();
bin getBin(int i);
//...
private:
vector<bin> bins;
};
#endif
错误
(This is line: vector<bin> getBins();)
C:\...\bins.h:34: error: type/value mismatch at argument 1 in template parameter list for 'template<class _Tp, class _Alloc> class std::vector'
C:\...\bins.h:34: error: expected a type, got 'bin'
C:\...\bins.h:34: error: template argument 2 is invalid
(This is line: bin getBin(int i);)
C:\...\bins.h:35: error: 'bin' does not name a type
(This is line: vector<bin> bins;)
C:\...\bins.h:43: error: expected a type, got 'bin'
C:\...\bins.h:43: error: template argument 2 is invalid
我没有与C++太多的经验;不过,我之前用这种方法使用过载体,没有任何问题。任何建议表示赞赏。
编辑:这与代码的所有其他部分注释掉。
你不需要使用命名空间std一个预处理指令 – Marlon
'后分号;在'头文件通常被认为是不好的,因为它在每个使用你的头文件的人身上强迫它们不知道。 – Flexo
问题出在你的程序中你没有发布的部分。请复制您的程序,并删除与此问题无关的每一行。请将生成的程序复制粘贴到您的问题中。查看http://sscce.org是为什么发布一个类似程序的程序不起作用。 –