![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Nov 2009
Posts: 6
Rep Power: 0
![]() |
Problem with pointer in function return
hi all ,
i have problem and three days just trying find out, but no result!! i have two diffirent classes: Xnode and Ynode in Ynode, i have method called tree() which it gets as argument - a reference of Xnode (as const) , and it calls its method to return one private variable xx. void Ynode::tree(const Xnode& x){
const Node* n=x.list();
std::cout << n->value;
}
const Node* Xnode::list() const {
const Node* nod=xx;
std:cout << nod->value;
return nod;
}can you tell me what's wrong? why the pointer is undefined in const Node* n=x.list(); ?? its little urgent!. thanks a lot. Last edited by Ancient Dragon; Nov 23rd, 2009 at 5:31 AM. Reason: replaced icode tags with code tags |
|
|
|
|
|
#2 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 7,021
Rep Power: 12
![]() |
Re: Problem with pointer in function return
Yep. You haven't learned about scope. You might want to Google it (disregard any links regarding mouthwash).
Incidentally, it isn't urgent. You might want to also Google Eric Raymond's "Smart Questions."
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers Politically Incorrect |
|
|
|
|
|
#3 |
|
Newbie
Join Date: Nov 2009
Posts: 6
Rep Power: 0
![]() |
Re: Problem with pointer in function return
hi,
Do you think i didnt try googling or learning before posting? i did. but this kind of Q is not easy to solve and needs epecially assistance from others who can advise. thanks anyway |
|
|
|
|
|
#4 |
|
PFO God In Training
![]() ![]() Join Date: Jun 2005
Location: near St Louis, MO. (USA)
Posts: 1,534
Rep Power: 6
![]() |
Re: Problem with pointer in function return
in list(), what is xx?
>>was undefined value - ...56923434. That's not undefined value, but uninitialized value. undefined means you tried to use a variable that had not been declared. uninitialized means you used a variable that had been declared but not set to anything; it just contains whatever random data was in memory at the time the variable was declared.
__________________
PFO's FAQ is here |
|
|
|
|
|
#5 | |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 7,021
Rep Power: 12
![]() |
Re: Problem with pointer in function return
I gave you the correct term to Google. Here are the first two paragraphs from the first hit for C++ scope:
Quote:
Search is the first part. The second is the ability to read and comprehend. The are requirements for a good programmer because the time economy is important.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers Politically Incorrect |
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| global vs local pointer with linked lists | aatyler | C | 7 | Sep 10th, 2009 8:02 AM |
| having problem need some help | gentleboy | C++ | 8 | Apr 4th, 2009 10:04 PM |
| simple pointer array w/ function crash | codylee270 | C | 8 | Dec 4th, 2005 9:28 PM |
| Return Strings in Function | hbweb500 | C# | 8 | Jul 10th, 2005 9:44 PM |
| Pointers in C (Part II) | Stack Overflow | C | 2 | Apr 29th, 2005 11:39 AM |