我在初始化頭文件中的結構向量時遇到問題。結構不匹配的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是爲什麼發佈一個類似程序的程序不起作用。 –