Re: error: invalid use of nonstatic data member
The|Godfather ha scritto:
class test1 :example{
class StatementInternals;
public:
test1();
private:
StatementInternals * stmt_internals;
};
<snip>
--------
test1.cpp
-------
#include <test1.h>
#include <test1I.h>
test1::StatementInternals::StatementInternals()
: length(0), select_statement(0)
{
stmt_counter=stmt_internals->giveIt(); // THE PROBLEM LINE IS THIS
ONE
There are two different errors here. Your compiler is apparently
reporting only the first one however.
Forget for a moment that StatementInternals is a nested class of test1
and that stmt_internals is private. Would that work? No, because in
order to use a non-static member of a class you need to provide an
*instance* of such class. For example:
void foo(test1* ptr)
{
stmt_internal; // ERROR: which stmt_internal?
ptr->stmt_internal; // OK: THE stmt_internal of *ptr
}
Your case is the same: you don't have an instance of class test1 to work
on and you can't use stmt_internals without providing one.
Don't be fooled by the fact that class StatementInternals is nested in
class test1. They are still two different classes and there is *no*
implicit containment relationship between them.
The other mistake is that stmt_internal is a pointer to an object of
class test1::StatementInternals, but that class does *not* have a
giveIt() member function. giveIt() was defined in class example and so
it's inherited by class test1, but StatementInternals does *not* inherit
from test1 (nor from example).
Morale: nesting doesn't imply neither containment nor inheritance.
HTH,
Ganesh
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]