Hello, I have a problem with the structure.

abridged version:

class AVL_Tree { private: std::string dirName;//имя директории в которой будет сохранена структура struct Tree_ // структура для представления узлов дерева { Key key; Tree_(Key k) { key = k; //тут был код сохранения , я его удалил чтобы не занимал место std::string dir=dirName; cout<<dir<<"место хранения структуры"<<endl; } }; Tree_ *root; } 

I do not understand why, but Tree_(Key k) does not see the dirName variable.

1) Severity Code Description C2327 'lib :: AVL_Tree> :: dirName': This is not a type name, static, or enumerator

2) Severity Code Description 'dirName': Undeclared identifier

Could you tell me what the problem is?

  • make the structure static - Duracell
  • Do not tell me what it will give? because the error did not disappear - Demolver

1 answer 1

Your designer does not know which object to contact dirName . Or specify an AVL_Tree object (passing it to the constructor, for example), or make dirName member of a class, not an object — that is, declare it as static and refer to it as AVL_Tree::dirName .

  • Can you give an example? it is not profitable for me to simply send and generally store dirName in a structure. only 1 time in the object. - Demolver
  • one
    @Demolver As I understand it, your Tree_ node is in some kind of AVL_Tree. As an option, add a field to the structure like AVL_Tree*avl; , and constructor do Tree_::Tree_(Key k, AVL_Tree*avl):avl(avl){...} - something like this. Then you will need to refer to avl->dirName as avl->dirName . On the objection that I don’t want to store an extra pointer in each Tree_ , I’ll ask a question about what to do if there are a dozen different trees in the program? How can Tree_ know which tree he is in? - Harry
  • And if to transfer in the designer of structure dirName ? or is it not a beautiful solution? - Demolver
  • @Demolver Possible. Less - if you want to pass on something else later, you will have to change a lot. - Harry