CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Mar 2011
    Posts
    4

    [solved] Code doesn't update

    Hello,

    I have some problems with a example that I am making. I want to:
    1: send a "pointer to an object" to a other object
    2: that object needs to call a function of the object that I send to him.

    I made this:
    Code:
    //this is a part of my class:
    
    class aanroepding {
    public:
    	void laatestzien() { std::cout << "some text"; } //this is the function that is getting called, only when I edit the text, it does not update. 
    };
     
    class vanafhieraanroepen {
    public:
    	void callfunctievanandereclass(aanroepding* obj) { obj->laatestzien(); } //this takes the pointer and cals a function of the object
    };
    
    // that is a part of the main() :
    
    vanafhieraanroepen testing4; //makes a object with the name testing4
    aanroepding* testing5 = new aanroepding; // makes a pointer that points to an object
    testing4.callfunctievanandereclass(testing5); //pass the pointer to testing4
    delete testing5; //deletes the pointer
    When I run it for the first time, then everything works fine, but when I change the text of this class:

    Code:
    class aanroepding {
    public:
    	void laatestzien() { std::cout << "some text"; } //this is the function that is getting called, only when I edit the text, it does not update. 
    };
    then he showes me the old text, so it does not update. Does some one see what I did wrong?
    Even when I call delete on the pointer obj, then it also does not work.
    Last edited by lauwdude; March 22nd, 2011 at 09:02 AM.

  2. #2
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,150

    Re: Code doesn't update

    I don't see a difference between the two laatestzien.
    How do you "edit" the text?
    Do you recompile after "editing" the text?
    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 ]

  3. #3
    Join Date
    Mar 2011
    Posts
    4

    Re: Code doesn't update

    Sorry, I mean:

    Code:
    class aanroepding {
    public:
    	void laatestzien() { std::cout << "some textasdasdasdasdasd"; } //this is the function that is getting called, only when I edit the text, it does not update. 
    };
    Yes I recompile

  4. #4
    Join Date
    Apr 2008
    Posts
    725

    Re: Code doesn't update

    show a complete compilable example that we can debug. Have you debugged? Does the line that you changed get executed?

    Maybe the code didnt actually get debugged. Maybe you have duplicate code somewhere that you didnt modify. Maybe... Without the whole picture, we are just guessing.

  5. #5
    Join Date
    Mar 2011
    Posts
    4

    Re: Code doesn't update

    Quote Originally Posted by Amleto View Post
    show a complete compilable example that we can debug. Have you debugged? Does the line that you changed get executed?

    Maybe the code didnt actually get debugged. Maybe you have duplicate code somewhere that you didnt modify. Maybe... Without the whole picture, we are just guessing.
    I putted everything in one file:

    Code:
    #include <iostream>
    
    using namespace std;
    
    class aanroepding {
    public:
    	void laatestzien() { std::cout << "some text"; } //this is the function that is getting called, only when I edit the text, it does not update. 
    };
    
    class vanafhieraanroepen {
    public:
    	void callfunctievanandereclass(aanroepding* obj); //this takes the pointer and calls a function of the object
    };
    
    void vanafhieraanroepen::callfunctievanandereclass(aanroepding *obj) { //this takes the pointer and calls a function of the object
    	obj->laatestzien(); 
    	delete obj;
    }
    
    int main() {
    	vanafhieraanroepen testing4; //makes a object with the name testing4
    	aanroepding* testing5 = new aanroepding; // makes a pointer that points to an object
    	testing4.callfunctievanandereclass(testing5); //pass the pointer to testing4
    	delete testing5; //deletes the pointer
    	system("pause");
    	return 0;
    }
    and I got an error, I added it to this post.
    I know for sure that this isn't good:
    Code:
    testing4.callfunctievanandereclass(testing5); //pass the pointer to testing4
    normaly you have a pointer, and in the pointer you store an address of the location of the real class. But if I try that way it gives me an error. So I realy don't know how to fix this :\

    edit:
    I mean that the "testing5" in "testing4.callfunctievanandereclass(testing5);" isn't good, but this was the only way the compiler accepted it, and I know that can not work this way. if I try it a other way he just say's that it is not good.
    Attached Images Attached Images  
    Last edited by lauwdude; March 22nd, 2011 at 08:47 AM.

  6. #6
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: Code doesn't update

    You're deleting testing5 in vanafhieraanroepen::callfunctievanandereclass, and again after the call to that function.

  7. #7
    Join Date
    Mar 2011
    Posts
    4

    Re: Code doesn't update

    Thanks, I did't see that :$

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured