Matrix.h
namespace Matrix
{
class mat
{
public:
mat(int row, int col);
const mat &operator=(const mat &rhs);
}
}
Matrix.cpp
Matrix::mat::mat(int row, int col)
{ // implementation here }
const Matrix::mat &Matrix::mat::operator=(const mat &rhs)
{ // implementation here }
上面的代碼將編譯沒有任何問題。問題是,我應該把名稱空間標識符放在參數前面,例如const mat operator=(const Matrix::mat &rhs);
和
const Matrix::mat Matrix::mat::operator=(const Matrix::mat &rhs)
?什麼是常規方式來做到這一點,爲什麼它會編譯而不添加標識符?
你可以這樣做,或者在這些方法周圍使用'命名空間Matrix {...}。我更喜歡後者。 – memo1288