943,913 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 2139
  • C++ RSS
You are currently viewing page 2 of this multi-page discussion thread; Jump to the first page
Dec 3rd, 2008
0

Re: Return a private member from a NOT friend class

try returning ' ' instead of " ", don't know why but something tells me it might work
Reputation Points: 92
Solved Threads: 16
Junior Poster
chococrack is offline Offline
149 posts
since Oct 2008
Dec 3rd, 2008
0

Re: Return a private member from a NOT friend class

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.
Reputation Points: 10
Solved Threads: 8
Junior Poster
sid78669 is offline Offline
195 posts
since Nov 2008
Dec 3rd, 2008
0

Re: Return a private member from a NOT friend class

Quote 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.
Reputation Points: 92
Solved Threads: 16
Junior Poster
chococrack is offline Offline
149 posts
since Oct 2008
Dec 3rd, 2008
0

Re: Return a private member from a NOT friend class

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:

C++ Syntax (Toggle Plain Text)
  1. int getPrivateThingy()
  2. {
  3. return privateThingy;
  4. }
Reputation Points: 92
Solved Threads: 16
Junior Poster
chococrack is offline Offline
149 posts
since Oct 2008
Dec 3rd, 2008
0

Re: Return a private member from a NOT friend class

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.
Reputation Points: 10
Solved Threads: 8
Junior Poster
sid78669 is offline Offline
195 posts
since Nov 2008
Dec 3rd, 2008
0

Re: Return a private member from a NOT friend class

Click to Expand / Collapse  Quote originally posted by chococrack ...
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:

C++ Syntax (Toggle Plain Text)
  1. int getPrivateThingy()
  2. {
  3. return privateThingy;
  4. }

This is the problem where i am stuck! it is not returning the privateThingy!! LOL
Reputation Points: 10
Solved Threads: 8
Junior Poster
sid78669 is offline Offline
195 posts
since Nov 2008
Dec 3rd, 2008
0

Re: Return a private member from a NOT friend class

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.
Reputation Points: 92
Solved Threads: 16
Junior Poster
chococrack is offline Offline
149 posts
since Oct 2008
Dec 3rd, 2008
0

Re: Return a private member from a NOT friend class

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).
Reputation Points: 92
Solved Threads: 16
Junior Poster
chococrack is offline Offline
149 posts
since Oct 2008
Dec 3rd, 2008
0

Re: Return a private member from a NOT friend class

Click to Expand / Collapse  Quote originally posted by chococrack ...
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:
C++ Syntax (Toggle Plain Text)
  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!
Reputation Points: 10
Solved Threads: 8
Junior Poster
sid78669 is offline Offline
195 posts
since Nov 2008
Dec 3rd, 2008
0

Re: Return a private member from a NOT friend class

Storm in a teacap. Totally absurd code and its "rationale":
c++ Syntax (Toggle Plain Text)
  1. Account data = new Account[arraySize];
Click to Expand / Collapse  Quote originally posted by sid78669 ...
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?
Reputation Points: 1234
Solved Threads: 347
Postaholic
ArkM is offline Offline
2,001 posts
since Jul 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: How can I use this code repeatedly?
Next Thread in C++ Forum Timeline: solving a quadratic equation





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC