Home > Back-end >  The following program that guild compilation mistakes, why. Class declaration and definition, inlini
The following program that guild compilation mistakes, why. Class declaration and definition, inlini

Time:10-06

The class OutClass.
The class Test
{
Public:
The Test f (t) Test;//ok?
Fp Test * * p (Test);//ok?
The Test * tp;//ok?
The Test t;//ok?
OutClass * Po;//ok?
OutClass mo;//ok?
OutClass fo (OutClass);//ok?
The inline OutClass * ifop (OutClass *) {};//ok?
The inline OutClass * ifo (OutClass) {};//ok?
The inline OutClass ifo (OutClass *) {};//ok?
The inline OutClass ifo (OutClass) {};//ok?
};

CodePudding user response:

 class OutClass. 
The class Test
{
Public:
The Test f (t) Test;//ok?
Fp Test * * p (Test);//ok?
The Test * tp;//ok?
The Test * t;//ok?
OutClass * Po;//ok?
OutClass * mo;//ok?
OutClass fo (OutClass);//ok?
The inline OutClass * ifop (OutClass *) {};//ok?
The inline OutClass * ifo (OutClass *) {};//ok?
};

Some of them are want to take a pointer that we can in the past, don't know meet your requirements

CodePudding user response:



For classes prior to declaration, because there is no class definition, also can't know the specific memory and use, as long as you don't use to the class definition, is not wrong,

The class OutClass.
The class Test
{
Public:
The Test f (t) Test;//ok?
Fp Test * * p (Test);//ok?
The Test * tp;//ok?
The Test t;//ok? Error: class cannot contain itself, which leads to cannot construct,
OutClass * Po;//ok?
OutClass mo;//ok? Wrong: need to know the definition of outclass here,
OutClass fo (OutClass);//ok? Function parameters or return values used in the class, here only function declarations, can not know the specific definition, forward, the statement can be
The inline OutClass * ifop (OutClass *) {};//ok?
The inline OutClass * ifo (OutClass) {};//ok? -- -- -- -- -- the function with the same name parameters, only the return value is different, is not suitable for heavy regulation,
The inline OutClass ifo (OutClass *) {};//ok?
The inline OutClass ifo (OutClass) {};//ok? Function with the same, only is not the same as the return value, it is no good, overloading rule is parameters must be different, can be overloaded
};
Several inline function, whether the return value, or the return pointer, in a statement, all not wrong, if the return value is, the return value of the statement is wrong,
But now the function is empty, the return of any thing, the compiler will have a warning: the function should return a value,

Note: the function of the class definition of statement does not need to know, to declare before, that a few empty inline function is pointless,
The inline OutClass ifo OutClass (a) {return fo (a); };//that is possible, do not need to know the class definition,


CodePudding user response:

Notice in class, define a function that is defined in the class has a function, and function implementation is not there, that is equivalent to a function declaration, the declaration is not to need to use class defined, a forward declaration,

CodePudding user response:

With a compiler, the compiler will prompt you, no?
  • Related