关于C++ inline的用法,这段代码哪出错了?

2025-05-10 23:39:37
推荐回答(3个)
回答1:

//selectors function using normal inline(outside the class)
//double X()const;//access x value (getter) 这里注释掉
//double Y()const;//access y value 这里注释掉
//getter功能:题目规定用 normal inline
inline     double X()const //   去掉point::
{
return m_x;
}
inline double Y()const   //   去掉point::
{
return m_y;
}

回答2:

setter想使用dealult inline
就需要在类中去实现。

void X(double newx){m_x=newx;}这个写在类中的话就没有问题了。

回答3:

inline double X()const;
inline double Y()const;//在类里直接声明为内联

};
类外:
double point::X()const
{
return m_x;

}
double point::Y()const
{
return m_y;
}