2

I have this class:

class BST
{
public:
   void insert(int val) { insert(node, val); }
private:
   void insert(std::shared_ptr<Node> node, int i);
   std::shared_ptr<Node> node = nullptr;
};

Here I have public function insert for class users. And private overloaded version of if. And when I want to call this function from driver code, in IntelliSence hint I have two overloads of this function. enter image description here

So if there is a way to hide private function from user?

273K
  • 29,503
  • 10
  • 41
  • 64
  • 3
    There is no way. The access control happens after the overload resolution. A compiler works in a such way. IntelliSense behaves similarly. – 273K Apr 30 '23 at 17:41
  • 3
    Perhaps give it a different name, like `insert_shared`? – BoP Apr 30 '23 at 17:45
  • It would be a dupe of https://stackoverflow.com/questions/9027338/how-to-hide-private-members-of-a-class, but that is 11 years old, smth might be changed since that time. – 273K Apr 30 '23 at 17:46

1 Answers1

5

You can use the macro __INTELLISENSE__ to hide class members from IntelliSense suggestions.

class BST {
 public:
  void insert(int val) { insert(node, val); }

 private:
#ifndef __INTELLISENSE__ 
  void insert(std::shared_ptr<Node> node, int i);
#endif

  std::shared_ptr<Node> node = nullptr;
};

The tip is giving here: Troubleshooting Tips for IntelliSense Slowness.

Unfortunately, this is not a good enough solution. It will hide suggestions even in the correct access scopes, in own class methods.

273K
  • 29,503
  • 10
  • 41
  • 64