- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
这里只是一个非常简短的问题。我正在使用虚函数从文本文件中读入。现在,它是虚拟的,因为一方面我希望这些值被标准化,而另一方面我不希望它们被标准化。我试过这样做:
bool readwav(string theFile, 'native');
因此理论上,如果使用“native”,则应调用此方法,但是,如果调用“double”,则调用该方法的不同版本。如果值为空,则相同,它应该只执行 native 选项。
第一个问题,为什么上面的声明不起作用?另外,这是最好的下山路线吗?或者,只使用一种在选项之间切换的类方法会更好吗?
谢谢:)
更新:
我哪里错了?
bool Wav::readwav(string theFile, ReadType type = NATIVE)
{
// Attempt to open the .wav file
ifstream file (theFile.c_str());
if(!this->readHeader(file))
{
cerr << "Cannot read header file";
return 0;
}
for(unsigned i=0; (i < this->dataSize); i++)
{
float c = (unsigned)(unsigned char)data[i];
this->rawData.push_back(c);
}
return true;
}
bool Wav::readwav(string theFile, ReadType type = DOUBLE)
{
// Attempt to open the .wav file
ifstream file (theFile.c_str());
cout << "This is the double information";
return true;
}
最佳答案
因为'native'
是多字符字符,不是字符串。不过,我会使用该函数的多个版本:
bool readwavNative(string theFile);
bool readwavDouble(string theFile);
或者至少一个 enum
作为第二个参数:
enum ReadType
{
ReadNative,
ReadDouble
};
//...
bool readwav(string theFile, ReadType type);
关于c++ - OO C++ - 虚拟方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12348909/
我相信 OO,但不至于应该使用不适当的设计/实现来实现“OO 兼容”。 那么,如何应对 Serlvet/EJB/DataContainer 分层架构: Servlet 接收请求并调用“业务层”(例如
我有一个员工分为两类(国内和国际)。我还有一个类Refund,是用来给员工退款的。我有一个名为银行账户的类,由 Refund 类用于退款。 现在我的直接设计是这样的: 员工界面,分国内和国际2个子类型
为什么基于类的 OO 而不是基于原型(prototype)的 OO 如此受欢迎?他们在学校教后者吗?尽管 Javascript 是基于原型(prototype)的,但大多数人主要在功能上使用它,或者通
为什么基于类的 OO 而不是基于原型(prototype)的 OO 如此受欢迎?他们在学校教后者吗?尽管 Javascript 是基于原型(prototype)的,但大多数人主要在功能上使用它,或者通
我找不到主要区别。我很困惑什么时候可以使用继承,什么时候可以使用子类型。我找到了一些定义,但它们不是很清楚。 在面向对象编程中,子类型化和继承有什么区别? 最佳答案 除了已经给出的答案,这里还有一个
我想在类中动态定义方法。我正在写一个跟踪器,比下面的框架稍微复杂一些,它也有状态意识,但这与我的问题无关。我写了一个 TraceSlave 类,它带有调用 sprintf 的跟踪方法,用文本\n 替换
如果你看过Going Deep shows of the Channel9最近,一个经常被提及的话题是mathematical duality在编程中。 TomasP 有一个不错的blog post关
关闭。这个问题是opinion-based .它目前不接受答案。 想要改进这个问题? 更新问题,以便 editing this post 可以用事实和引用来回答它. 关闭 8 年前。 Improve
我是软件设计原则的忠实粉丝,例如 固体 和 干 .面向对象软件设计还有哪些其他原则? 笔记。我不是在寻找诸如“评论您的代码”之类的答案,而是在寻找 OO 设计原则,例如 Uncle Bob 讨论的那些
我找不到主要区别。我很困惑什么时候可以使用继承,什么时候可以使用子类型。我找到了一些定义,但它们不是很清楚。 面向对象编程中的子类型和继承有什么区别? 最佳答案 除了已经给出的答案,这里还有一个 li
这个问题已经有答案了: Javascript: Do I need to put this.var for every variable in an object? (6 个回答) 已关闭 9 年前。
我正在构建一个应用程序,该应用程序在一个对象内有一个对象数组,而它的自身位于一个数组中。我希望能够从子对象访问父对象的属性。我知道我可以简单地通过索引引用父级,如下所示: var parents =
我有一个像这样的html页面 和 2 个像这样的 JavaScript 文件 /// /// /// $(document).ready(fu
我正在尝试用 javascript 做一个巨大的 Web 应用程序,如果我不想搞乱一切,我想我必须以面向对象的方式来做。因此,我进行了很多搜索,发现了很多在 JS 中声明类和创建实例的不同方法,例如环
我在理解 OO 模式如何工作时遇到了一些问题,我的讲师给了我以下问题,但我思考了一整天后无法解决它 我的问题的场景。 有一个名为“ShapeManager”的类,用于管理 Shape 对象。名为“Sh
关闭。这个问题是opinion-based .它目前不接受答案。 想改进这个问题?更新问题,以便 editing this post 可以用事实和引用来回答它. 1年前关闭。 Improve this
我正在阅读科学 paper关于 Robert martin 编写的 OO Design Quality Metrics。 在他的论文中,他描述了“一组指标,可用于衡量面向对象设计的质量,根据该设计的子
我有一个与 OOP 相关的问题。我有一个界面,说: class MyInterface { public int getValue(); } 在我的项目中,这个接口(interface)由 7
是否有更好的Pythonic/面向对象方法来选择在运行时执行哪个特定类方法,具体取决于对象的类型,因为使用 type() 方法不被认为优雅(?) 我为我正在使用的三种数据类型编写了以下代码。它基本上将
就 Perl OO 而言,-> 到底做了什么? 例如我打了一个主电话: $result = a::b->mymethod( ); 在我定义 mymethod() 的包中,我使用了以下内容: m
我是一名优秀的程序员,十分优秀!