Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [cdt-dev] Nested class Accessibility

Hi


If you are already visiting the AST, you can also visit the visibility labels (implement the corresponding visit() method and enable them) and remember the last visibility you have encountered on the way. You probably will need to have a stack of visibilities, as you might overwrite it in the nested classes. I'm not sure if there is already some functionality like this lingering somewhere. This is one possibility.


Otherwise, you can look for this information in the bindings, if you are familiar with them. ICPPClassType has a method getVisibility(IBinding). I guess you can call it on the "Enclosing" binding with the "Nested" binding as argument.


I would suggest the latter.


I hope this helps!
Thomas


Von: cdt-dev-bounces@xxxxxxxxxxx <cdt-dev-bounces@xxxxxxxxxxx> im Auftrag von Ming Cheng <chengm349@xxxxxxxxxxx>
Gesendet: Freitag, 29. Mai 2020 10:15:18
An: cdt-dev@xxxxxxxxxxx
Betreff: [cdt-dev] Nested class Accessibility
 
Hi,

Assume I have this class definition:

class Enclosing {      
   private:   
       int x;
     
   /* start of Nested class declaration */  
   class Nested {
      int y;   
      void NestedFun(Enclosing *e) {
        cout<<e->x;  // works fine: nested class can access 
                     // private members of Enclosing class
      }       
   }; // declaration Nested class ends here
}; // declaration Enclosing class ends here
  
Now ASTVisitor will give me callback "public int visit(IASTDeclaration decl)" for class Enclosing and later Nested. How can I get class Nested's accessibility within Enclosing? 

Thanks.
Ming

Back to the top