Original Post
Here is a simple C++ vs. Java question. In Java, why is it that two different classes can access each others'' public data members (without creating a class object), whereas in (Visual) C++, you get a compile error? I seem to recall that doing this in C++ is allowed just as it is in Java, but obviously the compile error says otherwise.
for example in Java, this is allowed:
class MyClassA
{
public int variableA = 1;
...
}
class MyClassB
{
...
void function()
{
int variableB = MyClassA.variableA;
}
}
but in C++, this isn''t allowed ("illegal use of this type as an expression"):
class MyClassA
{
public:
int variableA;
...
}
class MyClassB
{
public:
int variableB;
...
}
void MyClassB::function()
{
variableB = MyClassA.variableA;
}
