C++ Accessing variables in a function in one class from a different class
<p>I'm 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 I'm facing is that I'm 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 an output as 293e30 (address location)
Please guide me on how to this.</p>

<pre><code>Class1
{
public:
    membfunc()
    {
        int A;
        A = 10;
    }
}

Class2
{
public:
    membfunc2()
    {
        int B;
        B = A + 10;
    }
    membfunc3()
    {
        int C, D;
        C = A + 10;
        D = B + C;
    }
}
</code></pre>

<p>If i print variables, i expect to get 
<code>A = 10</code>, <code>B = 20</code>, <code>C = 20</code>, <code>D = 40</code>
But what I get is
<code>A = 10</code>, <code>B=(252e30) + 10</code></p>