compiler error in spite of correct code

A

arno

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 ^^^^^^^^^^^^
 
J

John Harrison

arno said:
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
 
I

Ivan Vecerina

....
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
 
K

Karthik Kumar

arno said:
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?
 
A

arno

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

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

arno
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top