Hello, Peter Oberberg wrote:
> Maybe I did not understand something fundamental about namespaces, > because I cannot make out the following behaviour. This is a C++ question, but we are in a g++ newsgroup here. What could be discussed is the error message of g++, which is not really helpful. I have never seen that message before. error: expected constructor, destructor, or type conversion before ?=? token This might be an artifact of the parser, it tries some cases, some unfamiliar case as the last one which has to match, and that is the message one gets. I don't know what the compiler tried last, where this message could match. The problem in the code is not difficult to see. > > Please consider the following code snippet (it is a simplified version > of what I want to do, in order to reproduce the error, actually the > namespace declaration is in a separate header file). > > // ================================================== > // Begin C++ code, file TTest.cc > > namespace TTest > { This is a definition, without initializer. > int value; > }; > This is an assignment outside of a function, which is not possible: > TTest::value = 1; > > // End C++ code > // ================================================== > This works: // ================================================== // Begin C++ code, file TTest.cc namespace TTest { extern int value; // declaration }; int TTest::value = 1; // definition with initializer, needs type int main() { TTest::value = 1; // assignment expression in a statement } // End C++ code // ================================================== > So where am I wrong in thinking, that TTest::value is an entity, I can > assign values to outside the namespace? There can only be one definition of TTest::value, maybe with initializers, and assignments may only happen inside of a function. Bernd Strieder _______________________________________________ help-gplusplus mailing list help-gplusplus@gnu.org http://lists.gnu.org/mailman/listinfo/help-gplusplus