Results 1 to 3 of 3
Hi everybody, I am new to C++ and encountered some kind of problem that can not be solved by myself, anybody who can provide some ideas would be greatly appriciated!
...
- 09-28-2007 #1Just Joined!
- Join Date
- Sep 2007
- Posts
- 2
Passing values in C++
Hi everybody, I am new to C++ and encountered some kind of problem that can not be solved by myself, anybody who can provide some ideas would be greatly appriciated!
Ok, I have three objects created in three different cpp files, I will name them as objA, objB and objC. objA contains objB, it is like a page object has a button object on it. Here is the code:
<objA.h>
private: const var* var1;
int var2;
<objA.cpp>
void objA::SomeHandlerFunction(const ButtonEvent& event)
{
var1 = objB.GetContent();
var2 = var1->GetContentID();
}
Now my big problem is how to pass the value of say var2 to objC? I need this value for further use. I used to get segmentation fault before, I figured out I need to allocate memory for the pointer var before using it, but it seems the correct value still can not be passed. If don't pass the value to objC and only use it within objA, everything will be fine.
May be my understanding of this problem is totally wrong, please help me figure out how to solve it, thank you so much, waiting for your reply!
cheers!
- 09-28-2007 #2
I do not understand your problem in the slightest. Do you mean that you need to somehow create an instance of objC and pass var2 to it?
This is the standard way of instantiating an object. Perhaps you may want to read up some more on Object-Oriented programming and constructors?Code:void objA::SomeHandlerFunction(const ButtonEvent& event) { var1 = objB.GetContent(); var2 = var1->GetContentID(); objC myC(var2); // or: objC *myC = new objC(var2); }DISTRO=Arch
Registered Linux User #388732
- 09-28-2007 #3Just Joined!
- Join Date
- Sep 2007
- Posts
- 2
thanks, that helps a lot, sorry for the kinda stupid question, again thank you!


Reply With Quote