Reputation: 1039
[I couldn't find a proper answer to this. Kindly point me to proper links if this is already answered.]
I know that it illegal to do something like this,
class Base
{
public:
virtual void funcFoo() = 0 {} //illegal. should be defined outside the class body
virtual ~Base() {}
};
But this works fine on VS2008. I want to know why this is disallowed by the standard?
On android, I see that I have to define the function inline like this,
inline void Base::funcFoo() {}
instead of just,
void Base::funcFoo() {}
what is the diference in implicit inlining and explicit inlining here? what is the compiler doing different?
Upvotes: 0
Views: 210
Reputation: 361352
That is ill-formed according to section §10.4/2 which says (in the note) that,
a function declaration cannot provide both a pure-specifier and a definition
[Example:
struct C {
virtual void f() = 0 { }; // ill-formed
};
—end example]
Hope it answers your question.
Now please refer to the first comment (below) made by @John Dibling, as unfortunately the answer to your "why" question isn't in the Standard, IF "that is ill-formed"
isn't an acceptable answer to you. The language grammar simply doesn't allow it.:-)
Upvotes: 4
Reputation: 490108
I don't think there is much of an answer to this. It came up once before (possibly on Usenet instead of SO -- I don't remember), so I did some looking. I didn't really come up with much of anything. As far as I can tell, that's how Bjarne originally devised it. Although it could be changed, I couldn't find any proposals to the committee that it be changed, nor any indication that the committee has even debated, discussed, or considered it at all. My guess would be that it's considered "good enough" the way it is, so nobody's willing to put in much (any?) effort to change it.
Upvotes: 1
Reputation: 26094
The first question is already answered -- the standard simply disallows it.
The second question is:
On android, I see that I have to define the function inline like this,
inline void Base::funcFoo() {}
instead of just,
void Base::funcFoo() {}
what is the diference in implicit inlining and explicit inlining here? what is the compiler doing different?
The difference is that the first variant can be placed in a header file, which can be included by more than one source file. The second variant must be place in exactly one source file.
Upvotes: 0