У меня есть такой шаблон, в частности, с публичной функцией Insert(), я не публикую здесь весь шаблон. :
Код: Выделить всё
struct WordItem {
string word;
vector documents;
WordItem(string w, string docName,int &c )
{
word = w;
DocumentItem doc(docName,c);
documents.push_back(doc);
}
};
template
class AVLSearchTree
{
private:
struct Node
{
Node* left;
Node* right;
int height;
Key key;
Value value;
Node(const Key&k, const Value& v)
: key(k), value(v), height(0), left(NULL), right(NULL) {}
};
Node* root;
void insertin(Node*& t, const Key& k, const Value& v)
{
if (t == NULL)
{
t = new Node(k, v);
}
else if (k < t->key)
{
// Inserted into left tree
insert(t->left, k, v);
if (height(t->left) - height(t->right) == 2)
{
if (k < t->left->key) // k was inserted to the left-left subtree
rotateWithLeftChild(t);
else
doubleWithLeftChild(t);
}
}
else if (k > t->key)
{
// Inserted into right tree
insert(t->right, k, v);
if (height(t->right) - height(t->left) == 2)
{
if (k > t->right->key)
rotateWithRightChild(t);// k was inserted to the right-right subtree
else
doubleWithRightChild(t);
}
}
//update the height of the node
t->height = max(height(t->left), height(t->right)) + 1;
}
public:
AVLSearchTree() : root(NULL) {}
~AVLSearchTree()
{
makeEmpty(root);
}
void insert(Key& key, Value& value)
{
insertin(root, key, value);
}
Код: Выделить всё
AVLSearchTree myTree;
string s = "someword";
string filename = "a.txt";
int initToOne = 1;
//WordItem* item = &WordItem(s, filename, initToOne);
WordItem* item(string s, string filename, int initToOne);
myTree.insert(s, item);
ошибка: невозможно преобразовать 'WordItem*(std::string, std:: string, int)' {также известный как 'WordItem*(std::__cxx11::basic_string, std::__cxx11::basic_string, int)'} в 'WordItem*&'
Я перепробовал почти все варианты, почему так происходит? Как я могу это исправить?
Подробнее здесь: https://stackoverflow.com/questions/783 ... -parameter
Мобильная версия