0
#include <utility>

struct A
{
    A(int x, int y)
    {
        using std::swap; // OK
        swap(x, y);
    }
};

struct B
{
    //
    // The line below is illegal:
    //
    using std::swap; 
    //
    // error : using declaration in class
    // refers into 'std::', which is not a class
    //

    B(int x, int y)
    {        
        swap(x, y);
    }
};

The question is embedded in the example above.

I just wonder:

Why does the C++ standard prohibit such a usage?

What's the rationale behind?

xmllmx
  • 39,765
  • 26
  • 162
  • 323
  • 4
    The C++ standard does not "prohibit" anything. C++ didn't start out as "write anything you want" language, with various things getting progressively prohibited, over time. This kind of a syntax has never been a part of C++, so you can't do it. This is like saying "why does the Oxford English dictionary prohibit the word 'fromblaz' from being a part of the language". It was never part of the language, that's all. – Sam Varshavchik Nov 30 '16 at 01:33
  • 1
    See also: http://stackoverflow.com/questions/4362831/scoped-using-directive-within-a-struct-class-declaration – Cody Gray - on strike Nov 30 '16 at 01:33

0 Answers0