GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 18-Jan-2009, 12:06
Sal Bruno Sal Bruno is offline
New Member
 
Join Date: Jan 2009
Posts: 5
Sal Bruno is on a distinguished road

How to access C++ data structure


I am new to C++ and need to know how to access (get/set or read/write) the prompt information from another module. Code and details to follow.

Module A.cc contains a data structure this:

CPP / C++ / C Code:

inode_state::inode_state(): parent (NULL), child (NULL), prompt ("%") {
}

Module A.h contains a data structure this:

CPP / C++ / C Code:

class inode_state {
   friend class inode;
   private:
      inode *parent;
      inode *child;
      string prompt;
   public:
      inode_state();
};


Last edited by LuciWiz : 18-Jan-2009 at 12:16. Reason: Corrected end [/cpp] tag
  #2  
Old 19-Jan-2009, 07:00
L7Sqr L7Sqr is offline
Member
 
Join Date: Jul 2005
Location: constant limbo
Posts: 234
L7Sqr is a jewel in the roughL7Sqr is a jewel in the rough

Re: How to access C++ data structure


If you are using a class you do not have access to then you can not access the private members of that class (unless you are supplied a formal way to do so). If you had access to the class you could just implement getters/setters for the data. If not, the only other way to get at the data is to have it declared as protected in the base class and make your own class that is a sub class of inode_state.
__________________
My personal site: Utilities for text processing, debugging, testing and plotting
  #3  
Old 19-Jan-2009, 09:16
Sal Bruno Sal Bruno is offline
New Member
 
Join Date: Jan 2009
Posts: 5
Sal Bruno is on a distinguished road

Re: How to access C++ data structure


Apparently the "friend class inode" allows inode to see the private members of inode_state, but not the converse. Therefore, I was informed there is a way to have access to the prompt class member. Please let me know if this makes sense. Again, I am new to C++.
  #4  
Old 19-Jan-2009, 12:27
L7Sqr L7Sqr is offline
Member
 
Join Date: Jul 2005
Location: constant limbo
Posts: 234
L7Sqr is a jewel in the roughL7Sqr is a jewel in the rough

Re: How to access C++ data structure


Lets start over.
What is it you are trying to do?
Do you have access to the inode_state class - i.e. can you edit its structure?
Do you have access to the inode class - can you edit its structure?

If can edit either of the above, it is a trivial task. Otherwise I'm not sure you will be able to do what you want (if I understand it correctly).
__________________
My personal site: Utilities for text processing, debugging, testing and plotting
  #5  
Old 19-Jan-2009, 14:33
Sal Bruno Sal Bruno is offline
New Member
 
Join Date: Jan 2009
Posts: 5
Sal Bruno is on a distinguished road

Re: How to access C++ data structure


Hello L7Sqr,

Thanks for being patient with me. I can access the inode_state and inode_class. I do not want to. So without change the .h and .cc files, how I update the prompt string member?
  #6  
Old 19-Jan-2009, 18:47
L7Sqr L7Sqr is offline
Member
 
Join Date: Jul 2005
Location: constant limbo
Posts: 234
L7Sqr is a jewel in the roughL7Sqr is a jewel in the rough

Re: How to access C++ data structure


If you can access those classes, your best course of action (and most direct) is to edit the classes to do what you need. Otherwise you run the risk of confusing not only yourself but others who use your code.
__________________
My personal site: Utilities for text processing, debugging, testing and plotting
  #7  
Old 19-Jan-2009, 23:55
Sal Bruno Sal Bruno is offline
New Member
 
Join Date: Jan 2009
Posts: 5
Sal Bruno is on a distinguished road

Re: How to access C++ data structure


Hello L7Sqr,

I can edit the class. I need to add two function calls, a set and get. If the class in the module.h file was written in the following manner ...

CPP / C++ / C Code:
class exit_status {
   private:
      static int status;
   public:
      static void set (int);
      static int get();
};

With the code written in module.cc like this...

CPP / C++ / C Code:
void inode_state::set (string new_prompt) {
   prompt = new_prompt;
}
   
string inode_state::get() {
   return prompt;
}

How would I make the call in the main program to set and get the prompt?
Last edited by LuciWiz : 20-Jan-2009 at 01:35.
  #8  
Old 20-Jan-2009, 01:39
LuciWiz's Avatar
LuciWiz LuciWiz is offline
Moderator
 
Join Date: Jul 2004
Location: Cluj-Napoca (Romania)
Posts: 1,032
LuciWiz is a jewel in the roughLuciWiz is a jewel in the roughLuciWiz is a jewel in the roughLuciWiz is a jewel in the rough

Re: How to access C++ data structure


Sal Bruno, please read the Guidelines from the link in my signature. The way you are trying to use code tags is wrong.

Thank you.
__________________
Please read these Guidelines before posting on the forum

"A person who never made a mistake never tried anything new."
Einstein
 
 

Recent GIDBlogAccepted for Ph.D. program by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Memory leak when nothing is happening... How can I even debug this ? Algar MS Visual C++ / MFC Forum 10 19-Nov-2007 08:17
[Include] Doubly-linked List dsmith C Programming Language 6 14-Apr-2006 14:12
Strange C++ code memory leakage problem gaoanyu C++ Forum 7 04-Nov-2005 09:09
[GIM] Data Module - Contact dsmith C Programming Language 2 27-Jan-2005 17:30
[CONTEST?]Data Structure Test dsmith C Programming Language 2 06-Jun-2004 16:13

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 06:46.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.