using declaration to introduce a name

Discussion in 'C++' started by mzdude, Oct 8, 2008.

  1. mzdude

    mzdude Guest

    I have the following code

    struct foo
    {
    operator std::string () const { return str;}
    std::string f() const {return str;}

    std::string str;
    };

    struct bar : private foo
    {
    using foo::eek:perator std::string;
    using foo::f;
    };

    void test()
    {

    bar b;
    std::string a = b; // Ok
    std::string a2 = b.f(); // Ok

    const bar b2;
    std::string a3 = b2; // Compile error
    std::string a4 = b2.f(); // Ok
    }

    My question is why does the compiler have a problem with the const
    for the operator but not the function.


    error XXXX: 'initializing' : cannot convert from 'const bar' to
    'std::basic_string<_Elem,_Traits,_Ax>'
    with
    [
    _Elem=char,
    _Traits=std::char_traits<char>,
    _Ax=std::allocator<char>
    ]
    No constructor could take the source type, or constructor
    overload resolution was ambiguous
     
    mzdude, Oct 8, 2008
    #1
    1. Advertising

  2. mzdude

    mzdude Guest

    On Oct 8, 3:55 pm, Victor Bazarov <> wrote:
    >
    > Because of the bug in the compiler, maybe?
    >
    > Post the same question to 'microsoft.public.vc.language' (you *are*
    > using MSVC, aren't you?)
    >

    Yes. I'm using VC8. That's what I wanted to know. Was it a compiler
    bug or a definition problem.
     
    mzdude, Oct 8, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Peng Yu
    Replies:
    0
    Views:
    1,163
    Peng Yu
    Aug 14, 2003
  2. Sander Zuidema

    Bazix introduce One Chip FPGA computer

    Sander Zuidema, Jul 11, 2005, in forum: VHDL
    Replies:
    3
    Views:
    667
    valentin tihomirov
    Jul 16, 2005
  3. priya
    Replies:
    3
    Views:
    1,124
    Ralf Hildebrandt
    Oct 8, 2005
  4. Philip Parker
    Replies:
    11
    Views:
    2,805
    Rufus V. Smith
    Jul 7, 2004
  5. junyangzou
    Replies:
    3
    Views:
    210
    Victor Bazarov
    Aug 21, 2013
Loading...

Share This Page