compiler error in spite of correct code

Discussion in 'C++' started by arno, Oct 6, 2004.

  1. arno

    arno Guest

    Hi all,
    if I compile the small example below without defining
    "VC6_STUPID_BEHAVIOUR" I get the following compiler error:
    error C2614: 'MyCString' : illegal member initialization: 'string' is
    not a base or member

    can somebody say me why??? In my opinion it should work in both
    variants. On Solaris and HP-UX it works fine.

    I have to work with MS VC++ 6.0 SP6

    best regards
    Arno

    // vvvvvvvvvvvvvvv snipp vvvvvvvvvvvvvvvv
    #include <string>
    #include <iostream>

    #ifdef VC6_STUPID_BEHAVIOUR
    using std::string;
    # define std_string string
    #else
    # define std_string std::string
    #endif

    class MyCString
    : public std_string
    {
    public:
    MyCString(const char *s_);
    : std_string(s_)
    {
    std::cout << "\"" << *this << "\"" <<
    std::endl;
    };
    };

    int main (int argc, char *argv[])
    {
    MyCString s(argv[0]);
    return 0;
    }
    // ^^^^^^^^^^^^ snipp ^^^^^^^^^^^^
     
    arno, Oct 6, 2004
    #1
    1. Advertising

  2. "arno" <> wrote in message
    news:...
    > Hi all,
    > if I compile the small example below without defining
    > "VC6_STUPID_BEHAVIOUR" I get the following compiler error:
    > error C2614: 'MyCString' : illegal member initialization: 'string' is
    > not a base or member
    >
    > can somebody say me why??? In my opinion it should work in both
    > variants. On Solaris and HP-UX it works fine.
    >
    > I have to work with MS VC++ 6.0 SP6
    >
    > best regards
    > Arno
    >


    VC++ 6 has many bugs, this is one of them.

    john
     
    John Harrison, Oct 6, 2004
    #2
    1. Advertising

  3. "arno" <> wrote in message
    news:...
    ....
    > can somebody say me why??? In my opinion it should work in both
    > variants. On Solaris and HP-UX it works fine.
    >
    > I have to work with MS VC++ 6.0 SP6

    ....
    > class MyCString
    > : public std_string
    > {
    > public:
    > MyCString(const char *s_);
    > : std_string(s_)

    I guess this is where VC6 chokes on std::string.
    Maybe a simple typedef within your class will do as a workaround:
    typedef std::string base_string;
    MyCString(const char *s_);
    : base_string(s_)



    This said: you shall not derive from std::string.

    Trust me, there always is a better way
    (containment or free functions).


    regards,
    Ivan
    --
    http://ivan.vecerina.com/contact/?subject=NG_POST <- email contact form
     
    Ivan Vecerina, Oct 6, 2004
    #3
  4. arno wrote:
    > Hi all,
    > if I compile the small example below without defining
    > "VC6_STUPID_BEHAVIOUR" I get the following compiler error:
    > error C2614: 'MyCString' : illegal member initialization: 'string' is
    > not a base or member
    >
    > can somebody say me why??? In my opinion it should work in both
    > variants. On Solaris and HP-UX it works fine.
    >
    > I have to work with MS VC++ 6.0 SP6
    >
    > best regards
    > Arno
    >
    > // vvvvvvvvvvvvvvv snipp vvvvvvvvvvvvvvvv
    > #include <string>
    > #include <iostream>
    >
    > #ifdef VC6_STUPID_BEHAVIOUR
    > using std::string;
    > # define std_string string
    > #else
    > # define std_string std::string
    > #endif
    >
    > class MyCString
    > : public std_string
    > {
    > public:
    > MyCString(const char *s_);


    Is the semilcolon (at the end of the previous line) misplaced?


    --
    Karthik.
    http://akktech.blogspot.com .
     
    Karthik Kumar, Oct 6, 2004
    #4
  5. arno

    arno Guest

    :
    > > public:
    > > MyCString(const char *s_);

    >
    > Is the semilcolon (at the end of the previous line) misplaced?


    Yes it is, but this is only a copy/paste error.

    arno
     
    arno, Oct 7, 2004
    #5
  6. arno

    arno Guest

    > VC++ 6 has many bugs, this is one of them.

    hi john,
    this means it works how exspected in VC 7.x?

    arno
     
    arno, Oct 7, 2004
    #6
  7. "arno" <> wrote in message
    news:...
    > > VC++ 6 has many bugs, this is one of them.

    >
    > hi john,
    > this means it works how exspected in VC 7.x?
    >


    I believe so.

    john
     
    John Harrison, Oct 7, 2004
    #7
    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. Yan
    Replies:
    0
    Views:
    1,146
  2. Ram
    Replies:
    0
    Views:
    2,857
  3. Skybuck Flying
    Replies:
    107
    Views:
    1,975
    Bruce Roberts
    Sep 26, 2005
  4. Replies:
    6
    Views:
    441
    Clever Monkey
    Jul 30, 2007
  5. Replies:
    5
    Views:
    590
    ThatsIT.net.au
    Jan 30, 2008
Loading...

Share This Page