你可以覺得像類成員函數:
ReturnType Function(TypeOfThisClass* this_, TypeOfParam param, ...)
( 您在std::thread
使用這種形式過於:(即把類PTR作爲參數)
class MyClass { void Function() { ; }; }
....
MyClass myClass;
std::thread(&MyClass::Function, &myClass);
)
所以你的成員是:
class MyClass{
....
friend MyClass operator*(const MyClass& this_, float &other)
{
return MyClass(this_.Data * other);
};
/*or MyClass operator*(float &other)
{
return MyClass(this->Data * other);
};, which is the same, except you use it with reference not pointer)*/
friend MyClass operator*(float &other, const MyClass& this_)
{
return this_ * other; //you can use the overloaded op. since it is defined above (first arg is class)
};
};
,如果你想訪問你的類protected
和private
數據(這應該是在OOP的情況下),你應該只使用friend
關鍵字。
是的,C++有免費的功能,我不會稱之爲解決方法。你的例子也是錯誤的。你不能將'0.4f'作爲'float'來傳遞。 – chris 2014-11-22 15:45:52