これは奇妙で、名前空間のプレフィックスを指定する場合にのみ「テキスト」フィールドでの Draw への 2 番目の呼び出しが機能するのにDraw
、オブジェクトでの最初の呼び出しは問題ない理由を見つけようとしていますか? shape
(すなわちShapes::Draw
):
#include <iostream>
namespace Shapes
{
class Shape {
public:
Shape() {}
virtual void InnerDraw() const {
std::cout << "Shape\n";
}
};
class Square : public Shape {
public:
void InnerDraw() { std::cout << "Square\n"; }
};
void Draw(char* text) { std::cout << text; }
void Draw(const Shape& shape) {
Draw("Inner: ");
shape.InnerDraw();
}
Shape operator+(const Shape& shape1,const Shape& shape2){
return Shape();
}
}
int main() {
const Shapes::Square square;
Shapes::Shape shape(square);
Draw(shape); // No need for Shapes::
Draw("test"); // Not working. Needs Shapes:: prefix
return 0;
}