0

I have come across this while reading a program in C++

inline Controller* Get_it() { // ... bla bla

I don't understand what this means. Does this imply the definition of Get_it function? I have searched for files where Get_it function is defined, but didn't find it. I think that the syntax a* b means that b is pointer to point to objects of structure a, but there is no stucture Controller. There is though a class Controller defined somewhere else.

Thank you in advance people. I am new to C++ and I am trying to understand.

Tony The Lion
  • 61,704
  • 67
  • 242
  • 415
  • Yes that is the definition of the function. It returns a pointer to a Control class object – Rob Apr 04 '13 at 09:42

5 Answers5

2

The function Get_it returns a Controller*. That's a pointer to a Controller, which is a type that must be declared somewhere above this point in the translation unit. The function is marked inline which is a hint to the compiler that it can inline the code, basically copying the function body into every place it is called from.

These two things are separate. The pointer is not inline, the function is.

Joseph Mansfield
  • 108,238
  • 20
  • 242
  • 324
1

The keyword inline affects what it being defined, and is only applicable to functions. Formally, it allows (and in fact requires) multiple definitions of the function. It is also a "hint" to the compiler that it should try to generate the code for the function directly at the call site, rather than to generate a call elsewhere. (The motivation for the formal definition is that the compiler typically cannot generate the code inline unless it has access to the definition.)

James Kanze
  • 150,581
  • 18
  • 184
  • 329
0

First, you should get yourself a good book on C++. Secondly, that is a pointer to a Controller object (a class in memory). It is returned by the function and the function is defined inline, meaning that it will be copied entirely to the callsite wherever it is called.

The inline word is a suggestion to the compiler to do inlining where sensible, but because you seem to indicate the function is defined inside the class declaration, it will be inlined by the compiler automagically.

Tony The Lion
  • 61,704
  • 67
  • 242
  • 415
0

The inline keyword doesn't apply to the pointer (the return value of the function), but to the function itself. So here you declare (and define) an inline function which returns a pointer-to-Controller.

0

The inline keyword defines an method as inline1, no matter where it get's implemented. The signature above means, that the function Get_it() returns an pointer to an Controller object. The function itself is inline.

1 Inline means, that the method get's not addressed through an vtbl, but get's directly allocated in the object's memory, so that there is no indirection when calling the method on an object instance, but the object instance itself grows in memory size.

Carsten
  • 11,287
  • 7
  • 39
  • 62