Sign in to follow this  
_nomad_

[C++] variable visibility problem

Recommended Posts

alright let's say i have the following code:
class A {
  private:
    B* test;

  public:
    void testPass (B* aParam) {
      test = aParam;
    }

    void testFunc() {
      test->DoSomething();
    }
}


class B {
  public:
    int testInt;

  void DoSomething() {}
}


main() {
  B* myB = new B();
  A* myA = new A();

  myA->testPass(B);
}
how come i get error about illegal access to test, when i use testFunc() in class A? i've run debug and the watcher says: "CXX0030: Error: expression cannot be evaluated" (i'm using vc++.net) what am i doing wrong? (btw, the code above was rewritten from notepad, it's derived from another project code and rewritten for simplicity/discussion/example).

Share this post


Link to post
Share on other sites
Besides the missing DoSomething(), semicolins, using B before it's been defined... nothing obviously wrong to me.

Quote:
how come i get error about illegal access to test, when i use testFunc() in class A? i've run debug and the watcher says it is: "CXX0017: Error: symbol "" not found"


So you're saying you're not getting compiler errors, just debug errors? If you're using VS6, it's likely just one of it's many bugs, a clear sign you should upgrade :-).

If you're getting compiler/linker errors, please copy and paste the actual code and errors (including their line numbers) which are giving you this problem. Otherwise, it's like like a lost tourist in Paris trying to find the airport with a New York subway map.

Either way, without the actual source, our ability to help deal with any problems is fairly low.

Share this post


Link to post
Share on other sites
the code i placed here was remade and isn't directly from the original source code (since it's too huge to past here). although i am doing the same thing (hence the missing semicolons, etc.)

so nothing's wrong with it right?

Share this post


Link to post
Share on other sites
Quote:
Original post by _nomad_
alright let's say i have the following code:

class A {
private:
B* test;

public:
void testPass (B* aParam) {
test = aParam;
}

void testFunc() {
test->DoSomething();
}
}


class B {
public:
int testInt;

void DoSomething() {}
}


main() {
B* myB = new B();
A* myA = new A();

myA->testPass(myB); // <--- i think you went wrong here. compare to your original code
}



how come i get error about illegal access to test, when i use testFunc() in class A? i've run debug and the watcher says: "CXX0030: Error: expression cannot be evaluated" (i'm using vc++.net)

what am i doing wrong?

(btw, the code above was rewritten from notepad, it's derived from another project code and rewritten for simplicity/discussion/example).


Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this