Why is this invalid?
Code:class T
{
jclass myClass = NULL;
};
Printable View
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.
Has everything to do with it, though I may have said it in a very strange way.Quote:
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
Is jclass a pointer?
Apparently:Quote:
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?Quote:
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.
Even one more reason typedefs are so incredibly evil. There was no hint that it was a pointer here. Misleading typedef name, as well.
Don't do it! In this case, it's far better to not use a typedef, even if it means not being consistent.