小编Mic*_*ele的帖子

C++方法重载:基本和派生参数

在网上搜索后,我找不到这个问题的答案:

我有这个重载的方法:

foo(Base* base);
foo(Derived* derived);
Run Code Online (Sandbox Code Playgroud)

在这种情况下,"Derived"是"Base"的子类.
我打电话的时候:

foo(new Derived());
Run Code Online (Sandbox Code Playgroud)

我注意到总是调用第一个重载方法,而我想实现相反的结果(调用以"Derived*"对象作为参数的方法).

怎么解决这个?谢谢.

编辑:

好的,这是我的实际情况:

我有一个UIWidget和一个UIScoreLabel类.UIScoreLabel派生自UIWidget.我还有一个GameEvent类(B​​ase)和一个P1ScoreGameEvent类(Derived).

UIWidget:

virtual void handleGameEvent(GameEvent* e) { printf("ui_widget"); }
Run Code Online (Sandbox Code Playgroud)

UIScoreLabel:

virtual void handleGameEvent(P1ScoreGameEvent* e) { printf("ui_score_label"); }
Run Code Online (Sandbox Code Playgroud)

这是电话:

UIWidget* scoreLabel = new UIScoreLabel();
scoreLabel.handleGameEvent(new P1ScoreGameEvent());
Run Code Online (Sandbox Code Playgroud)

输出:

ui_widget
Run Code Online (Sandbox Code Playgroud)

我不明白我做错了什么.

c++ inheritance overloading

5
推荐指数
1
解决办法
3180
查看次数

Visual Studio 2010:dll丢失

我用谷歌搜索了一整天,我疯了

嗯,这是我的问题:我编写了我的vs项目,我已经指定了所有的"include"(通过选择项目属性 - >配置属性 - > VC++目录)和所有extern库目录(以相同的方式).然后我通过选择项目属性 - >链接器 - >输入 - >附加依赖项并添加所有.lib文件路径来指定所有其他库.我按F7,它编译没有错误.我运行该项目和..系统错误:缺少libsndfile-1.dll.

没关系,所以我打开了vs控制台,我转到了libsndfile-1.def(和libsndfile-1.lib)路径,我执行了:"lib.exe libsndfile.def".在这里我得到另一个错误:"LINK:致命错误lnk1104 lib.exe,无法打开libsndfile.lib"

我试图从网上下载libsndfile.dll,但它仍然无法正常工作.我也尝试将所有库放在我的源文件中的Visual Studio中..但是再一次,没办法.

我哪里错了?

先感谢您

编辑:我见过vs没有找到其他的dll!

c++ dll linker-errors visual-studio-2010 libraries

4
推荐指数
1
解决办法
1万
查看次数