-3
class btree{
 public:
 int non,vor;
 string str;
 struct tree{
   int data;
   struct tree *lnode;
   struct tree *rnode;
    };
};
int main(){
}

how to access structure type pointer lnode in main is it even possible help????

  • 1
    What, exactly, are you asking about? Just create an instance, of said `struct`, and do whatever you want with the variable? `btree::tree t; t.lnode = /*whatever*/;`? – Algirdas Preidžius Sep 17 '19 at 13:53
  • lnode is a pointer type variable , how can i access it with dot operator i.e myTree.node.lnode=10; i cannot do such type of assignment neither can i assign an address of another node using dot(.) operator – Ansari Aasif Sep 17 '19 at 14:12
  • "_i cannot do such type of assignment neither can i assign an address of another node using dot(.) operator_" I am sorry, but what? `lnode` is a pointer, yes. Hence, you couldn't do `lnode.data = 10;`, but what is stopping from doing `btree::tree t; t.lnode = new btree::tree;`? You can't use dot operator on a pointer, but such example doesn't do that. I use dot operator on an instance, not on pointer. Consider learning from a [good C++ book](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list). – Algirdas Preidžius Sep 17 '19 at 15:27

1 Answers1

1

You defined the struct tree, but didn't actually put any into your btree. Do this instead:

class btree {
public:
    int non, vor;
    string str;
    struct tree {
        int data;
        struct tree *lnode;
        struct tree *rnode;
    } node; // note the "node" that was added, now btree contains a struct tree named "node"
};

Access it like this:

int main() {
    btree myTree;
    myTree.node.data = 10;
}
Blaze
  • 16,736
  • 2
  • 25
  • 44
  • The same way. `myTree.node.lnode` and `myTree.node.rnode`. – Blaze Sep 17 '19 at 14:00
  • lnode is a pointer type variable , how can i access it with dot operator i.e myTree.node.lnode=10; i cannot do such type of assignment neither can i assign an address of another node using dot(.) operator – Ansari Aasif Sep 17 '19 at 14:10
  • By making a `struct tree` (in a constructor/method of `btree` because `struct tree` isn't going to be visible outside of that). Then you assign that `struct tree` to `myTree.node.lnode` and then you can do `myTree.node.lnode->data = 10;` – Blaze Sep 17 '19 at 14:13