作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我如何在 cpp 中比较两个类与 void* ?我比较日和月。我可以在 compare_dayOfYear 函数中做什么?
这是我的课:
class DayOfYear
{
public:
DayOfYear(int newMonth,int newDay);
//Initializes the month and day to arguments.
DayOfYear(int newMonth);
//Initializes the date to the first of the given month.
DayOfYear();
//Initializes the date to January 1.
// Accessors
int getMonthNumber( );
//Returns 1 for January, 2 for February, etc.
int getDay( );
// Mutators
int setMonthNumber(int newMonth);
//Set 1 for January, 2 for February, etc.
int setDay(int newDay);
private:
int month;
int day;
};
bool compare_dayOfYear(const void * firstValue, const void * secondValue)
{
//I compare day and month
//What can I do here
}
我如何在 cpp 中比较两个类与 void* ?我比较日和月。我可以在 compare_dayOfYear 函数中做什么?
最佳答案
如果您确定已经传递了 DayOfYear
对象,那么您可以只转换 void
指针。
bool compare_dayOfYear(const void * firstValue, const void * secondValue)
{
DayOfYear* firstDayOfYear = static_cast<DayOfYear*>(firstValue);
DayOfYear* secondDayOfYear = static_cast<DayOfYear*>(secondValue);
//compare..
}
关于c++ - 如何在 cpp 中将两个类与 void* 进行比较,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33329439/
我是一名优秀的程序员,十分优秀!