我的头文件中有一个声明为private
的数组。当我尝试从main
将值放入其中时,我得到错误,说它是私有的,并从初始化列表中为数组赋值。
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
int main(){
ArraySet<string> bag;
bag.items = { "a", "b", "c"};
return EXIT_SUCCESS;
}
项目在我的标题中定义为:
template <typename ItemType>
class ArraySet : public SetInterface<ItemType>{
private:
ItemType items[CAPACITY];
static const int CAPACITY = 6;
这是不正确的方法吗?我是模板的新手。谢谢!