Topic: inline declaration: seeking clarification
Author: Ashok Chowdhary <ashokc>
Date: 1995/07/19 Raw View
kuehl@uzwil (Dietmar Kuehl) wrote:
>"class X {
>public:
> int f();
>}
>
>void k(X *p) {
> int i = p->f();
>}
>
>inline int X::f() {
>..
>}"
>
>The definition of X::f() is said to be ill-formed:
>
The inline definition will not be ill-formed if the function K(..) does not
uses
the inline function.
As for as declaring the function in class' body and then declaring it inline is
concerned it is perfectly leagal, and thats how it is usually done. If you dont
declare the function in the class' body then it will not be there in its
interface anyway.
Author: kuehl@uzwil (Dietmar Kuehl)
Date: 1995/07/17 Raw View
Hi,
in the secion "Function Specifiers" (7.1.2; dcl.fct.spec) of the C++
Draft the following is found (reduced to the stuff meaningful for my
question...):
"class X {
public:
int f();
}
void k(X *p) {
int i = p->f();
}
inline int X::f() {
..
}"
The definition of X::f() is said to be ill-formed:
"Declares X::f as an inline function
A call appears before X::f is defined
ill-formed"
My question is: Is this ill-formed ONLY because X::f() was used in
k(X*) before the definition of "inline int X::f()"? I thought that this
would already be ill-formed because X::f() was declared in the class
body of X and then redeclared to be inline where X::f() is defined. Can
somebody clarify whether this would also be ill-formed if X::f() wasn't
used by k(X*)?
Thanks in advance
dk
--
http://www.informatik.uni-konstanz.de/~kuehl
dietmar.kuehl@uni-konstanz.de
I am a realistic optimist - that's why I appear to be slightly pessimistic
Author: clamage@Eng.Sun.COM (Steve Clamage)
Date: 1995/07/18 Raw View
In article 146k@eurybia.rz.uni-konstanz.de, kuehl@uzwil (Dietmar Kuehl) writes:
>
>"class X {
>public:
> int f();
>}
>
>void k(X *p) {
> int i = p->f();
>}
>
>inline int X::f() {
>...
>}"
>
>The definition of X::f() is said to be ill-formed:
>
> "Declares X::f as an inline function
> A call appears before X::f is defined
> ill-formed"
>
>My question is: Is this ill-formed ONLY because X::f() was used in
>k(X*) before the definition of "inline int X::f()"?
Yes.
>I thought that this
>would already be ill-formed because X::f() was declared in the class
>body of X and then redeclared to be inline where X::f() is defined.
No. You don't have to say "inline" on the declaration, but only on
the definition. You do have to provide the definition before the first
use of the function.
---
Steve Clamage, stephen.clamage@eng.sun.com