Inlining could not be called unlikely, and the code size will grow [-Winline], but will not use the built-in

very new to c ++.

Here is my user-defined class fmiNode: (fmi.h)

class fmiNode
{
public:
    fmiNode(std::string NodeName,int Address)
    {
        this->name = NodeName;
        this->address = Address;
    }

    std::string GetName()
    {
    return this->name;
    }

    int GetAddress()
    {
    return this->address;
    }

private:
    std::string name;
    int address;
};

Here is my main method (fmi.c)

int main (int argc, char *argv[])
{
  fmiNode node1("NodeA",4);
  fmiNode node2("NodeB",6);
  fmiNode node3("NodeC",8);
  fmiNode node4("NodeD",10);

  while(1)
  {
      MainLoop();
  }
}

If I only instantiate one fmiNode object, everything is fine. but the following 3 triggers a warning:

 warning: inlining failed in call to ‘fmiNode::fmiNode(std::string, int)’: call is unlikely and code size would grow [-Winline]

What am I doing wrong here.

EDIT:

So, I have to define my class as follows :?

class fmiNode
{
public:
    fmiNode(std::string NodeName,int Address);

    std::string GetName()
    {
    return this->name;
    }

    int GetAddress()
    {
    return this->address;
    }

private:
    std::string name;
    int address;
};

fmiNode::fmiNode(std::string NodeName,int Address)
{
    this->name = NodeName;
    this->address = Address;
}

Cheers, Reese

+4
source share
1 answer

If you define a function (constructor, in your case) inside the class definition, the result will be the same as defining it outside the class with a keyword inlineaccording to the C ++ standard:

7.1.2.3 , ,

, inline, , main - , .

: , , EDIT, . , .cpp, .

+5

Source: https://habr.com/ru/post/1608650/


All Articles