| | |
Return a private member from a NOT friend class
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
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!
•
•
•
•
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.
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
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)
int getPrivateThingy() { return privateThingy; }
I would love to change the world, but they won't give me the source code
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.
Error Screen
Please take a look to better understand the problem i am facing.
Live free.... Die Hard!
•
•
•
•
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)
int getPrivateThingy() { return privateThingy; }
This is the problem where i am stuck! it is not returning the privateThingy!! LOL Live free.... Die Hard!
•
•
•
•
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).
C++ Syntax (Toggle Plain Text)
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!
Storm in a teacap. Totally absurd code and its "rationale":
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?
c++ Syntax (Toggle Plain Text)
Account data = new Account[arraySize];
•
•
•
•
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.
![]() |
Similar Threads
- Help with Friend Functions (C++)
- stuck on a member function for a class (C++)
- Passing Objects (C++)
- Question about private scope (C++)
- C++ que (C++)
- friend functions (C++)
- Help me for friend classes and using templates (C++)
- Please I Need U Again (C++)
- Simple Class Question (C++)
- accessing private data members (C++)
Other Threads in the C++ Forum
- Previous Thread: How can I use this code repeatedly?
- Next Thread: solving a quadratic equation
| Thread Tools | Search this Thread |
api array based beginner bitmap c++ c/c++ calculator char class classes code coding compile compiler console conversion count database delete deploy desktop developer directshow dll download dynamic email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news node number output parameter pointer problem program programming project python random read recursion recursive return sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






