Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » C / C++ IDE (CDT) » Indexer shows error when there is none(Indexer shows error when trying to access private members from a nested class)
Indexer shows error when there is none [message #1803294] Tue, 26 February 2019 12:52 Go to next message
Henning Gessner is currently offline Henning GessnerFriend
Messages: 2
Registered: February 2019
Junior Member
Consider the following declaration:

class outer {

public:

     class inner {

     private:
          outer m_parent;
     public:
          inner(outer* parent): 
               m_parent(parent) 
          {}

          int GetMeSome() {
               return parent->m_some;
          }
     };

private:

     int m_some;
};



The method GetMeSome has access to the private member m_some because it's a nested class. Unfortunately every version of the CDT Indexer so far shows this as an error (m_some is not visible).

Am I wrong? Is there a version where this is fixed? Or should this be reported as a bug?
Re: Indexer shows error when there is none [message #1803585 is a reply to message #1803294] Tue, 05 March 2019 05:04 Go to previous messageGo to next message
David VavraFriend
Messages: 1426
Registered: October 2012
Senior Member
You didn't define things properly.
1) m_parent should be a pointer to outer
2) you need to use m_parent instead of parent in GetMeSome
     class inner { 
     private:
          outer * m_parent;
:
:
     public:
:
:
          int GetMeSome() {
               return m_parent->m_some;
          }


[Updated on: Tue, 05 March 2019 05:07]

Report message to a moderator

Re: Indexer shows error when there is none [message #1803590 is a reply to message #1803585] Tue, 05 March 2019 08:00 Go to previous messageGo to next message
Henning Gessner is currently offline Henning GessnerFriend
Messages: 2
Registered: February 2019
Junior Member
OK, you're right, my example wasn't perfectly written. I just meant to illustrate a streight forward case. But even given those corrections:

class outer {

public:

     class inner {

     private:
          outer* m_parent;
     public:
          inner(outer* parent): 
               m_parent(parent) 
          {}

          int GetMeSome() {
               return m_parent->m_some; //this will be shown as an error by the CDT but not by gcc
          }
     };

private:

     int m_some;
};


The issue is still the same.
Re: Indexer shows error when there is none [message #1803621 is a reply to message #1803590] Tue, 05 March 2019 16:21 Go to previous message
David VavraFriend
Messages: 1426
Registered: October 2012
Senior Member
You'll have to be more specific.
What errors are you seeing?
With the changes I listed, I get a clean compile and the Indexer is happy.

0:45:09 **** Build of configuration Debug for project innerOuter ****
make all 
Building file: ../src/innerOuter.cpp
Invoking: GCC C++ Compiler
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/innerOuter.d" -MT"src/innerOuter.o" -o "src/innerOuter.o" "../src/innerOuter.cpp"
Finished building: ../src/innerOuter.cpp
 
Building target: innerOuter
Invoking: GCC C++ Linker
g++  -o "innerOuter"  ./src/innerOuter.o   
Finished building target: innerOuter
 
10:45:10 Build Finished. 0 errors, 0 warnings. (took 1s.69ms)


UPDATE
You do realize that actually accessing GetMeSome will be tricky since there is no inner member?

I made some mods to get around this and ran the code.
index.php/fa/35014/0/
Hello World
GetMeSome returns 25

[Updated on: Tue, 05 March 2019 17:04]

Report message to a moderator

Previous Topic:Need to add a C++ file to an existing C project
Next Topic:Request guidance for include path management
Goto Forum:
  


Current Time: Wed Apr 24 16:13:05 GMT 2024

Powered by FUDForum. Page generated in 0.03062 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top