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).
[C++] variable visibility problem
alright let's say i have the following code:
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()?
the problem is still the same, why can't i access test in testFunc()?
Besides the missing DoSomething(), semicolins, using B before it's been defined... nothing obviously wrong to me.
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.
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.
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?
so nothing's wrong with it right?
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).
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement