-
March 25th, 2019, 09:51 PM
#1
How to edit original object through object* temp that points to original object?
So if I have an Object called Friend with a member called name.
I do
Code:
Friend* f1;
Friend* temp;
for(int i =0; i<2; i++){
f1->name = "BILL";
if(i == 0)
temp = f1;
if(i == 1)
temp->name = "LARRY";
}
When I iterate through my friend vector it still returns
BILL
BILL
instead of:
Larry
BILL
How can I make it return the above?
-
March 26th, 2019, 06:56 AM
#2
Re: How to edit original object through object* temp that points to original object?
1. Where and what is your so called "vector"?
2. W hatis the relationship between pointer to Friend object (Friend* f1) and a "vector"?
Victor Nijegorodov
-
March 26th, 2019, 08:08 AM
#3
Re: How to edit original object through object* temp that points to original object?
...where do you initialise f1 and increment it?
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
March 27th, 2019, 03:05 AM
#4
Re: How to edit original object through object* temp that points to original object?
Please post compilable code.
What's the definition of your Friend class?
Where do you define your vector?
You are using f1 which is uninitialized.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|