X
Xavier Decoret
The following code does not compoile with gcc-3.2.3
namespace dummy
{
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Interface of Foo
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
class Foo
{
public:
friend bool operator==(const Foo& f0,const Foo& f1);
private:
int a_;
};
}
//************************************************************
// Implementation of Doo
//************************************************************
bool
operator==(const dummy::Foo& f0,const dummy::Foo& f1)
{
return f0.a_ == f1.a_;
}
After a while, I figured that operator== is actually declared in
namespace dummy:: so the compiler error is legitimate. Therefore I can
fix the implementation with:
bool
dummy:
perator==(const dummy::Foo& f0,const dummy::Foo& f1)
{
std::cout<<"in dummy:
perator=="<<std::endl;
return f0.a_ == f1.a_;
}
But then I am quite surprise that the following does compile:
int
main(int,char**)
{
dummy::Foo f0;
dummy::Foo f1;
return f0 == f1;
}
Because it should not find the operator== since namespace dummy is not
opened. But I am sure that it is the one called (thanks to the cout).
Then I tried to make operator== be in global namespace with
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Interface of Foo
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
friend bool :
perator==(const Foo& f0,const Foo& f1);
//************************************************************
// Implementation of Doo
//************************************************************
bool
operator==(const dummy::Foo& f0,const dummy::Foo& f1)
{
std::cout<<"in :
perator=="<<std::endl;
return f0.a_ == f1.a_;
}
But then it refuses to compile with:
main.C:11: `bool operator==(const dummy::Foo&, const dummy::Foo&)'
should have
been declared inside `::'
So my question is: is my concern legal? Do I really want to have
operator== in namespace dummy? Is it legal that gcc finds that there is
an dummy:
perator== even if the namespace is not opened?
Thanks for insights.
--
+-------------------------------------------------+
| Xavier Décoret - Post Doct |
| Graphics Lab (LCS) - MIT |
| mailto: (e-mail address removed) |
| home : http://www.graphics.lcs.mit.edu/~decoret|
+-------------------------------------------------+
namespace dummy
{
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Interface of Foo
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
class Foo
{
public:
friend bool operator==(const Foo& f0,const Foo& f1);
private:
int a_;
};
}
//************************************************************
// Implementation of Doo
//************************************************************
bool
operator==(const dummy::Foo& f0,const dummy::Foo& f1)
{
return f0.a_ == f1.a_;
}
After a while, I figured that operator== is actually declared in
namespace dummy:: so the compiler error is legitimate. Therefore I can
fix the implementation with:
bool
dummy:
{
std::cout<<"in dummy:
return f0.a_ == f1.a_;
}
But then I am quite surprise that the following does compile:
int
main(int,char**)
{
dummy::Foo f0;
dummy::Foo f1;
return f0 == f1;
}
Because it should not find the operator== since namespace dummy is not
opened. But I am sure that it is the one called (thanks to the cout).
Then I tried to make operator== be in global namespace with
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Interface of Foo
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
friend bool :
//************************************************************
// Implementation of Doo
//************************************************************
bool
operator==(const dummy::Foo& f0,const dummy::Foo& f1)
{
std::cout<<"in :
return f0.a_ == f1.a_;
}
But then it refuses to compile with:
main.C:11: `bool operator==(const dummy::Foo&, const dummy::Foo&)'
should have
been declared inside `::'
So my question is: is my concern legal? Do I really want to have
operator== in namespace dummy? Is it legal that gcc finds that there is
an dummy:
Thanks for insights.
--
+-------------------------------------------------+
| Xavier Décoret - Post Doct |
| Graphics Lab (LCS) - MIT |
| mailto: (e-mail address removed) |
| home : http://www.graphics.lcs.mit.edu/~decoret|
+-------------------------------------------------+