| | |
referencing an object
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Aug 2008
Posts: 91
Reputation:
Solved Threads: 0
I just have one question, when you have a class that is defined:
If in the main you said class box b(a); it would work as expected. But I don't understand how that makes sense. How can you set the adress of the object to another object. It would make sense to set it to another object's adress. Or is it that the reference operator is being used differenly than as an adress getter?
C++ Syntax (Toggle Plain Text)
class box{ public: int *value; box() { value=new int; *value=0; }; box(box &c) {*value=*c.value;}; };
line 10 is wrong. Why is value a pointer? From the class constructure it appears to be just a single integer, and you don't need a pointer for that
And get rid of those stars on line 10.
And get rid of those stars on line 10.
C++ Syntax (Toggle Plain Text)
class box{ public: int value; box() { value=0; }; box(box &c) {value=c.value;}; };
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
•
•
Join Date: Aug 2008
Posts: 91
Reputation:
Solved Threads: 0
Sorry I was working on complex copies when I screwed line 10 up, but what my real focus was was:
If in the main you said class box b(a); it would work as expected. But I don't understand how that makes sense. How can you set the adress of the object to another object. It would make sense to set it to another object's adress. Or is it that the reference operator is being used differenly than as an adress getter?
If in the main you said class box b(a); it would work as expected. But I don't understand how that makes sense. How can you set the adress of the object to another object. It would make sense to set it to another object's adress. Or is it that the reference operator is being used differenly than as an adress getter?
![]() |
Similar Threads
- 0x8004010F "The operation failed. An object could not be found" Outlook 2003 (Windows NT / 2000 / XP)
- Object creation question (C++)
- this pointer (JavaScript / DHTML / AJAX)
- Help referencing a file at desired intervals (VB.NET)
- Object Oriented Design (PHP)
- How do you do efficient array (de)referencing? (Perl)
- Help on Assignment (Java)
- Calling Object Methods within a LinkedList (Java)
Other Threads in the C++ Forum
- Previous Thread: Overload operator with one operand.
- Next Thread: Beginners Trouble
Views: 388 | Replies: 5
| Thread Tools | Search this Thread |
Tag cloud for C++
6 api application array arrays assignment beginner binary bitmap c++ c/c++ calculator char class classes code coding compile compiler console conversion convert count data database delete developer display dll email encryption error file forms fstream function functions game generator getline givemetehcodez graph homeworkhelper iamthwee ifstream image input int java lazy lib loop looping loops map math matrix memory multidimensional multiple newbie news node number output parameter pointer problem program programming project proxy python random read recursion recursive reference return sort sorting string strings struct template templates text tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






