This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

[Q] g++2.95.2 BUG Namespace and scoping


/*
  Hi!

  newsgroups: 
	      comp.lang.c++
              gcc@gcc.gnu.org
              gcc-bugs@gcc.gnu.org

  [Q] g++2.95.2 BUG Namespace and scoping

  Here's another example of (I guess g++ bug) in namespace
implementation.
  It seems that scoping in different namespaces and using directive
odesn't
  work well. Or is it my error?

  Let suppose we have generic output operator operator<< that implements
  virtual friend idiom, and every class implements its own virtual
  member function called output for the same purpose.

  The problem arises when the generic operator<< is called for the class
  from some other member function.

  Any ideas??

  Thanx a lot for Your time

  Miljenko
*/

# include <iostream>

namespace Operators
{
  template <class T>
    std::ostream& operator<< (std::ostream& os, const T& t)
    {
      t.output(os);
      
      return os;
    };
};

namespace Classes
{
  class X
  {
  private: 
  public:
    void output(std::ostream& os) const
      { 
	os << "X::output \n" ; 
	return; 
      };
  };
  
  template <class type>
    class Y
    {
    private: 
    public:
      void output(std::ostream& os) const
	{ 
	  os << "Y<Type >::output \n" ; 
	  return; 
	};
      void foo() const
	{
	  using namespace Operators;
	  /* ! OK */
	  /* 
	     doesn't work?!?!
	     Why can't compiler find it??
	   */
	  std::cout << (*this);
	  return;
	};
    };
};


int test()
{
  Classes::X x1;

  using Classes::X;
  X x2;

  using namespace Classes;
  using namespace Operators;

  /* OK */
  cout << x1;
  cout << x2;

  Y<int > yi1_;
  Y<X >   yx1_;

  yi1_.foo();
  yx1_.foo();

  /* OK */
  cout << yi1_;
  cout << yx1_;

  return 0;
};

int main()
{
  using Classes::X;
  using namespace Operators;

  X x1;
  X x2;

  /* OK */
  cout << x1;
  cout << x2;

  return test();
}



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]