Jump to content
  • Advertisement
Sign in to follow this  
_nomad_

[C++] variable visibility problem

This topic is 4621 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
Guest Anonymous Poster
There is no DoSomething in B?

Share this post


Link to post
Share on other sites
oops, sorry i forgot to put dosomething() in B in code above.

the problem is still the same, why can't i access test in testFunc()?

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
i've solved it...the problem was in other parts of the code, but is somewhat related to what Alpha_ProgDes mentioned too.

thanks! :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!