Why is this invalid?
Code:class T { jclass myClass = NULL; };
Why is this invalid?
Code:class T { jclass myClass = NULL; };
Because assignment would make 'myClass' static. (And a non-const static member is only a declaration--meaning it must be declared and assigned outside of the class.)
Soma
If you want it to be a regular member, you would do this in all of your constructors:Although it really depends on jclass and how it can be constructed. I have a feeling you can't just assign or initialize it with NULL unless it was a pointer.Code:class T { T() : myClass(NULL) { } };
Huh? Marking myClass static would make it static. Assignment has nothing to do with it.
It's invalid because the designers of C++ didn't include it in the C++ standard. The reasons are probably lost in time. Perhaps nobody thought of suggesting it. Perhaps it was deemed redundant, and the complexity of defining the semantics in relation to initializer lists not worth it. Perhaps people thought that not having all initialization in the same place (the constructor initializer list) would make the code harder to read.
Java's designers added direct initializers, but subtle aspects guiding such a decision are very different in Java than in C++.
I'm quite sure there was a proposal to add Java-style direct initializers to C++. I wonder what happened to it ...
Ah, found it.
Seems like it will be in the next standard.
All the buzzt!
CornedBee
"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law
Has everything to do with it, though I may have said it in a very strange way.Marking myClass static would make it static. Assignment has nothing to do with it.
Assignment of a structure members inline, in the tradition of C syntax, actually requires 'static'; everything else you see is actually an extension--that virtually every compiler allows.
Edit: Ah, I just realized that this is the same person... so this isn't a class but a pointer to a class.
Soma
Last edited by phantomotap; 04-17-2008 at 05:06 PM.
Is jclass a pointer?
Apparently:Is jclass a pointer?
http://cboard.cprogramming.com/showt...ghlight=jclass
Soma
So you mean, if the OP has seen inline assignment, it was for statics?Assignment of a structure members inline, in the tradition of C syntax, actually requires 'static';
OK, that makes a lot more sense. But might as well be complete: inline assignment works for static integral constants, nothing else.
All the buzzt!
CornedBee
"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law