内联调用不太可能失败,代码大小将增长[-Winline],但不使用内联
inlining failed in call to unlikely and code size would grow [-Winline] but not using inline
c++新手。
下面是我的用户定义的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;
};
这是我的主要方法(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();
}
}
如果我只实例化一个fmiNode对象,一切都很好。但是下面的3会引发警告:
warning: inlining failed in call to ‘fmiNode::fmiNode(std::string, int)’: call is unlikely and code size would grow [-Winline]
我哪里做错了。
编辑:所以我应该这样定义我的类:?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;
}
欢呼,里斯
如果您在类定义中定义函数(在您的例子中是构造函数),则结果与使用inline
关键字在类外部定义它相同,根据c++标准:
在类定义内定义的函数是内联函数
所以编译器得到了inline
的提示,但由于警告消息中的原因,认为将构造函数内联到main
是一个坏主意,所以它给了你警告。
Update:是的,您应该在EDIT中定义类以避免此警告。更好的是,将定义放入.cpp文件中,以避免多个定义错误。
相关文章:
- C++我的数学有什么问题,为什么我的代码不能正确循环
- 代码在main()中运行,但在函数中出现错误
- 在VS代码中交叉编译Windows与Linux上的MinGW的SDL程序
- 编译包含字符串的代码时遇到问题
- 我在c++代码中生成了一个运行时#3异常
- 如何在linux终端中同时编译和运行c++代码
- 为cl.exe(Visual Studio代码)指定命令行C++版本
- 在Linux for Windows上编译C++代码时出错
- 我的字符计数代码计算错误.为什么
- 孤立代码块在结构中引发异常
- 在编译C++代码(具有dlib和opencv)到WASM时面临问题
- 为什么我的C#代码在调用回C++COM直到Task时会暂停.等待/线程.加入
- 处理小于cpu数据总线的数据类型.(c++转换为机器代码)
- 此代码是否违反一个定义规则
- 为什么我的代码在输出中增加了93天
- 我的简单if-else语句是如何无法访问的代码
- 使用动态分配的数组会导致代码分析发出虚假的C6386缓冲区溢出警告
- 为什么在这个代码结束循环中没有得到结束
- gcc -O3 标志导致 -Winline "调用不太可能,代码大小会增长"警告
- 内联调用不太可能失败,代码大小将增长[-Winline],但不使用内联