|
-
November 12th, 2016, 01:08 PM
#1
acessing multi variables declared and initialised in one class from a different class
Im trying to code a program with multiple classes such the one of the class reads the variables from a text file and the other classes use these variables for further processing.
The problem im facing is that im having trouble passing the variables from one class to another class, i did try "friend" class and also tried to use constructors but failed
to get the desired output.
The best i could do was
suppose i have class 1 and class 2, and i have a variable "A=10" declared and initialised in class 1, with the help of constructor i inherit it in class 2;
when i print it in class 1, it gives a correct output as 10 but when i print it in class 2 it gives a output as 293e30 (adress location)
Please guide me on how to this.
Thank you in advance
Code:
Class 1
{
public:
membfunc()
{
int A;
A=10;
}
}
Class 2
{
public:
membfunc2()
{
int B;
B=A+10;
}
membfunc3()
{
int C, D;
C=A+10;
D=B+C;
}
}
the expected output when printed should be
A=10, B=20, C=20, D=40.
but the output which im getting is
A=10, B=(262e12)+10
Last edited by 2kaud; November 12th, 2016 at 01:21 PM.
Reason: Added code tags
Tags for this Thread
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
|