0

Hello,

I am a newbee in C++. I am trying to have a connection setup and trying to access private varaibles of a class. Please look at my piece of code below. Any comments would be greatly appreciated.
Basically, I want to access two private varaibles from MyClass into AnotherClass(myNewClass = new MyClass(?, ?)).

Thanks.
Amy

//start of header
MyClass.h
class MyClass{
public:
//constructor
MyClass(xyz* const Var1_X, mno* Var2_M);

private:
xyz* const PrivateVar1;
mno* const PrivateVar2;
}
//end of header

//start of source
MyClass.cpp
MyClass(xyz* const Var1_X, mno* const Var2_M):PrivateVar1(Var1_X),PrivateVar2(Var2_M)
{
}
//end of source

//start of another source
AnotherClass.cpp
Class AnotherClass{
private:
MyClass* myNewClass;

public:
myNewClass = new MyClass(how do i get those two private varaibles here?)
//end of another source

Edited by CplusplusNewBee: clarity

2
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by CplusplusNewBee
0

Could you give an example of how I do that in my case. Also, is there a way to do it ONLY by modifying AnotherClass.cpp or AnotherClass.h file and not modiying any other .cpp files above?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.