JaeJun LEE
JaeJun LEE

Reputation: 1334

How to disable auto-inserted 'inline' keyword in Visual Studio?

I love the Move definition location refactoring feature of Visual Studio 2015 except one thing. It automatically insert inline keyword ahead of function definition. So I always had to remove them by my self.

It is like this.

Before refactoring.

class GameLoop
{
public:
    void drawGame() {

    }
};

After refactoring(Move definition location)

//GameLoop.h
class GameLoop
{
public:
    void drawGame();
};
//GameLoop.cpp
inline void GameLoop::drawGame() {

}

Anybody knows how to disable this auto inline keyword?

Thanks.


For whom doesn't know where is this feature.

  1. Move cursor on the method you want refactor

  2. [Edit]->[Refactor]->[Move Definition Location]

or

  1. Press Ctrl+. shortcut and select Move Definition Location

Upvotes: 16

Views: 1422

Answers (1)

CasualCay
CasualCay

Reputation: 45

According to https://learn.microsoft.com/en-us/cpp/ide/refactoring/move-definition-location?view=msvc-140 it seeems as if its function is to move from source to header file, not vice versa.

However, the inline keyword for non-template functions in the source file - as you describe - is semantically correct, since the function definition within the class definition is implicitly inline, but it is not really a desirable behavior. I agree. I guess you could post this as an improvement issue to the VS devs.

On a sidenote, what I observed for template functions was (in VS2019):

  1. Move function definition from within the class body to outside the class body in the header file.
  2. Move function definition back from outside the class body to inside.
  3. back and forth in header file.

This behavior has much more merit in my opinion.

Upvotes: 3

Related Questions