Topic: Namespace / "Using" with function signature


Author: brangdon@cix.co.uk (Dave Harris)
Date: Mon, 4 Jun 2001 21:18:02 GMT
Raw View
stephen.clamage@sun.com (Stephen Clamage) wrote (abridged):
> That is correct. Using declarations apply only to names, not to
> individual objects or functions. Putting just one of an overloaded set
> of functions into the current scope is more likely to be an error than
> a reasonable programming practice.

Why?

If it is reasonable to have private inheritance and using declarations at
all, it seems reasonable to have:

    class my_readonly_container : private vector<int> {
    public:
         // Note: const versions only.
         using vector<int>::begin() const;
         using vector<int>::end() const;

         //...
    };


> If you really want to bring just some of an overloaded set of
> functions into the current scope, write an inline forwarding function:

Surely that is just as error-prone, if not more so, because it involves
more redundant repetition.

  Dave Harris, Nottingham, UK | "Weave a circle round him thrice,
      brangdon@cix.co.uk      |   And close your eyes with holy dread,
                              |  For he on honey dew hath fed
 http://www.bhresearch.co.uk/ |   And drunk the milk of Paradise."

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]





Author: Stephen Clamage <stephen.clamage@sun.com>
Date: Sun, 3 Jun 2001 20:15:00 GMT
Raw View
On Wed, 23 May 2001 09:25:47 GMT, Helmut Zeisel <helmut.zeisel@aon.at>
wrote:

>My compiler (GCC 2.95.2) says that
>it is not allowed to make a using declaration
>including function signature:

That is correct. Using declarations apply only to names, not to
individual objects or functions. Putting just one of an overloaded set
of functions into the current scope is more likely to be an error than
a reasonable programming practice.

If you really want to bring just some of an overloaded set of
functions into the current scope, write an inline forwarding function:

namespace A { void f(int); void f(double); }
inline void f(double d) { A::f(d); }


---
Steve Clamage, stephen.clamage@sun.com

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]





Author: Helmut Zeisel <helmut.zeisel@aon.at>
Date: Wed, 23 May 2001 09:25:47 GMT
Raw View
My compiler (GCC 2.95.2) says that
it is not allowed to make a using declaration
including function signature:

namespace A
{
  void f(int);
  void f(double);
};

namespace B
{
  void f(int);
  void f(double);
};

using A::f(int);
using B::f(double);

g++ t.cxx:

t.cxx:13: parse error before `('
t.cxx:14: parse error before `('

Is there some special reason why this is not allowed?

Helmut Zeisel

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]