-1
我有我的C++ ..我要大一这种方式,因为它的工作,学校代码有点问题..C++运算符重载[]
我有模板命名目录
template <typename T>
class Catalog
{
struct Item{
T* _product;
unsigned int _amount;
Item* _next = nullptr;
};
Item* _head;
Item* _actual;
Item* _last;
int _size;
void init()
{
this->_size = 0;
this->_head = nullptr;
this->_actual = nullptr;
};
public:
Catalog(void)
{
this->init();
};
T*& operator[](unsigned int){
Item* node = this->_head;
for (int i = 0; i < this->_size; i++)
{
if (i == pos)
{
return &node->_product;
}
node = node->_next;
}
return nullptr;
};
};
这是一个结构,在那里我有项目,在项目我有指针数组下一个..
我tryed喜欢这个
Catalog<Products> *catalog = new Catalog<Products>();
Products *pr1 = new ProductA(5, "jmeno", 5);
catalog->Add(pr1, 5);
Products* ct = catalog[0];
在我的情况下,Visual Studio是报告这个错误
IntelliSense: no suitable conversion function from SemestralniPrace::Catalog<Products>" to "Products *" exists
我要纠正操作[],所以我可以用我的目录一样,我需要..或更正主代码..
这对例如,我在类目录中有更多的功能,但它不是这个问题的重要..
有人可以帮我请..即使建议是对我有好处。我对此感到绝望。
感谢和抱歉我的英语,它不是我的母语。
'catalog'变量是指针,尝试'(*目录)[0]'或尝试声明为'目录目录;'代替(和操作的方式'catalog.Add(PR1,T);' ) –
jsantander
哦,谢谢,现在它正在工作。我使用(*目录)[0] ..我几乎没有使用C++的经验,而且它只在学校,所以我不知道如何纠正。 – JAttanonRadar