“错误:在构造函数中用作初始化程序的数组”

时间:2016-12-06 01:06:35

标签: c++ oop data-structures

由于某种原因,我的PassServer对象的构造函数总是使用GCC给出“用作初始化程序的数组”错误,只是指向构造函数的第一行。完整的错误是:

passserver.cpp: In constructor âPassServer::PassServer(std::size_t)â:
passserver.cpp:10:58: error: array used as initializer
PassServer::PassServer(std::size_t size) : passwords(size)
                                                         ^
In file included from hashtable.h:56:0,
             from passserver.h:15,
             from passserver.cpp:2:
hashtable.hpp: In instantiation of âcop4530::HashTable<K, V>::HashTable(size_t) [with K = std::basic_string<char>; V = std::basic_string<char>; size_t = long unsigned int]â:
passserver.cpp:10:58:   required from here
hashtable.hpp:13:16: error: array used as initializer
: currentSize{0}
               ^

即使您取出: passwords(size),它仍然会导致相同的编译错误。 以下是相关的代码块:

passserver.h:

#include "hashtable.h"
...
class PassServer {
public:
PassServer(size_t size = 101);
...
private:
HashTable<string, string> passwords;
...

hashtable.h:

...
public:
HashTable(size_t size = 101);
std::vector< std::list< std::pair<K, V> >* >* bucketVector;
...
private:
size_t currentSize;
...

hashtable.hpp:

template <typename K, typename V>
HashTable<K, V>::HashTable(size_t n) : currentSize{0} {
...
bucketVector = new std::vector< std::list<key_value>* >(prime_below(n), NULL);
...

如果需要提供更多,我会更新。这是一项任务,所以我试图不显示与我的错误无关的内容。提前谢谢。

0 个答案:

没有答案