dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: How to edit original object through object* temp that points to original object?

Hybrid View

  1. #1
    Join Date
    Mar 2019
    Posts
    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?

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,380

    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

  3. #3
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    6,697

    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++17 Compiler: Microsoft VS2019 (16.1.3)

  4. #4
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,148

    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.
    Marc Gregoire - NuonSoft (http://www.nuonsoft.com)
    My Blog
    Wallpaper Cycler 3.5.0.97

    Author of Professional C++, 4th Edition by Wiley/Wrox (includes C++17 features)
    ISBN: 978-1-119-42130-6
    [ http://www.facebook.com/professionalcpp ]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)