Return a private member from a NOT friend class

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Oct 2008
Posts: 118
Reputation: chococrack is on a distinguished road 
Solved Threads: 14
chococrack's Avatar
chococrack chococrack is offline Offline
Junior Poster

Re: Return a private member from a NOT friend class

 
0
  #11
Dec 3rd, 2008
try returning ' ' instead of " ", don't know why but something tells me it might work
I would love to change the world, but they won't give me the source code
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 106
Reputation: sid78669 is an unknown quantity at this point 
Solved Threads: 4
sid78669's Avatar
sid78669 sid78669 is offline Offline
Junior Poster

Re: Return a private member from a NOT friend class

 
0
  #12
Dec 3rd, 2008
actually the problem is not in returning the data. The problem lies in Accessing private members of teh Account class by public member functions of the same class. For eg, getFirstName() in Account is unable to access customer, visual studio spits out a Access violation error stating that the memory could not be read. this is the problem i need help with.
Live free.... Die Hard!
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 118
Reputation: chococrack is on a distinguished road 
Solved Threads: 14
chococrack's Avatar
chococrack chococrack is offline Offline
Junior Poster

Re: Return a private member from a NOT friend class

 
0
  #13
Dec 3rd, 2008
Originally Posted by Microsoft
Use the Call Stack window to work your way back up the call stack, looking for corrupted data being passed as a parameter to a function. If that fails, try setting a breakpoint at a point before the location where the access violation occurs. Check to see if data is good at that point. If so, try stepping your way toward the location where the access violation occurred. If you can identify a single action, such as a menu command that led to the access violation, you can try another technique: set a breakpoint between the action (in this example, the menu command) and the access violation. You can then look at the state of your program during the moments leading up to the access violation.

You can use a combination of these techniques to work forward and backward until you have isolated the location where the access violation occurred. For more information, see Using the Call Stack Window.
http://msdn.microsoft.com/en-us/libr...5h(VS.80).aspx


So meh.. wants us to look at parameters first I take it
Last edited by chococrack; Dec 3rd, 2008 at 11:47 am.
I would love to change the world, but they won't give me the source code
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 118
Reputation: chococrack is on a distinguished road 
Solved Threads: 14
chococrack's Avatar
chococrack chococrack is offline Offline
Junior Poster

Re: Return a private member from a NOT friend class

 
0
  #14
Dec 3rd, 2008
If its just a problem with retreiving the private member, why not just create a public function within that class to grab the private value and return it:

  1. int getPrivateThingy()
  2. {
  3. return privateThingy;
  4. }
I would love to change the world, but they won't give me the source code
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 106
Reputation: sid78669 is an unknown quantity at this point 
Solved Threads: 4
sid78669's Avatar
sid78669 sid78669 is offline Offline
Junior Poster

Re: Return a private member from a NOT friend class

 
0
  #15
Dec 3rd, 2008
Actually the call stack is not able to diagnose it either!! here's a screen shot of the error:

Error Screen

Please take a look to better understand the problem i am facing.
Live free.... Die Hard!
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 106
Reputation: sid78669 is an unknown quantity at this point 
Solved Threads: 4
sid78669's Avatar
sid78669 sid78669 is offline Offline
Junior Poster

Re: Return a private member from a NOT friend class

 
0
  #16
Dec 3rd, 2008
Originally Posted by chococrack View Post
If its just a problem with retreiving the private member, why not just create a public function within that class to grab the private value and return it:

  1. int getPrivateThingy()
  2. {
  3. return privateThingy;
  4. }

This is the problem where i am stuck! it is not returning the privateThingy!! LOL
Live free.... Die Hard!
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 118
Reputation: chococrack is on a distinguished road 
Solved Threads: 14
chococrack's Avatar
chococrack chococrack is offline Offline
Junior Poster

Re: Return a private member from a NOT friend class

 
0
  #17
Dec 3rd, 2008
Well thats not very nice of it then :<

What class is getData function in and what does it look like?
Last edited by chococrack; Dec 3rd, 2008 at 12:16 pm.
I would love to change the world, but they won't give me the source code
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 118
Reputation: chococrack is on a distinguished road 
Solved Threads: 14
chococrack's Avatar
chococrack chococrack is offline Offline
Junior Poster

Re: Return a private member from a NOT friend class

 
0
  #18
Dec 3rd, 2008
Also, whats the value of strlen(customer) at that point? Make sure its not falling off the array (just as an extra thing to look at possibly).
I would love to change the world, but they won't give me the source code
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 106
Reputation: sid78669 is an unknown quantity at this point 
Solved Threads: 4
sid78669's Avatar
sid78669 sid78669 is offline Offline
Junior Poster

Re: Return a private member from a NOT friend class

 
0
  #19
Dec 3rd, 2008
Originally Posted by chococrack View Post
Also, whats the value of strlen(customer) at that point? Make sure its not falling off the array (just as an extra thing to look at possibly).
Finally you get it! LOL! thanks bud! well the thing is like this. When the function is called, the getFirstName() is looking at the following line:
  1. savings[pos].getFirstName(st);

The problem is, I am unable to get why I am not getting the value equal to savings[8].getFirstName(st) as the pos is 8. Can you help on that?

As a final help, i'm attaching the main that I am using with my program:

a34main.cpp

I am sorry to ask for help, but my professor says that its against the college policy to help Before the due date! DUMB!!!

Anyway, please try to see if I have screwed up the function, or have screwed something else!
Live free.... Die Hard!
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 2,001
Reputation: ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of 
Solved Threads: 343
ArkM's Avatar
ArkM ArkM is offline Offline
Postaholic

Re: Return a private member from a NOT friend class

 
0
  #20
Dec 3rd, 2008
Storm in a teacap. Totally absurd code and its "rationale":
  1. Account data = new Account[arraySize];
Originally Posted by sid78669 View Post
I tried to do that as a final resort because even public functioncs of the Account class are giving errors while reading into the customer, private member of Account. I get a Access violation saying the memory could not be read. Any suggestions? It seems like my Array, savings is not working properly.
Are you sure that an even number of errors helps you to write correct codes? You have run-time errors. Why you are trying to play with program syntax in that case? Access violations do not bear a relation to a private or public member access rules. Have you ever seen the Debug menu choice?
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC