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.
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.
};
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.
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.
Last edited by lauwdude; March 22nd, 2011 at 08:47 AM.
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.