use*_*671 1 c++ parameters default-value
我是C++的新手(来自C#背景),我有一个带有以下签名的函数
void AddBenchNode(ref_ptr<Group> root ,ref_ptr<Node> benches, bool setAttitude = false, float scale_x =.15, float scale_y =15, float scale_z = 15, int positionx = 250, int positiony = 100, int positionz =0 )
{
}
Run Code Online (Sandbox Code Playgroud)
但是当我尝试调用下面的代码时,我得到一个错误,表示函数不带4个参数.
//then I try to call my function like so
AddBenchNode(root, benches, false, 250);
Run Code Online (Sandbox Code Playgroud)
但我得到以下错误消息
错误C2660:'AddBenchNode':函数不带3个参数
会不会理解C++如何做到这一点呢?
检查.hpp文件中的原型.它可能被宣布为
void AddBenchNode(ref_ptr<Group> root ,ref_ptr<Node> benches, bool setAttitude,
float scale_x, float scale_y, float scale_z, int positionx,
int positiony, int positionz);
Run Code Online (Sandbox Code Playgroud)
编辑:标题中的原型应该是
void AddBenchNode(ref_ptr<Group> root ,ref_ptr<Node> benches, bool setAttitude = false, float scale_x =.15, float scale_y =15, float scale_z = 15, int positionx = 250, int positiony = 100, int positionz =0 );
Run Code Online (Sandbox Code Playgroud)
然后你的cpp文件应该只有
void AddBenchNode(ref_ptr<Group> root ,ref_ptr<Node> benches, bool setAttitude, float scale_x, float scale_y, float scale_z, int positionx, int positiony, int positionz)
{
}
Run Code Online (Sandbox Code Playgroud)
也就是说,默认参数在原型中,而不在实际定义中.
| 归档时间: |
|
| 查看次数: |
616 次 |
| 最近记录: |