🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

3 total messages Started by Bob White Wed, 28 Feb 1996 18:55
Namespaces within class definition???
#3544
Author: Bob White
Date: Wed, 28 Feb 1996 18:55
18 lines
1288 bytes
Assuming that the "string" class is properly defined in namespace "std", is it 
legal to do the following:

class xyz : public std::string {
}

I am trying to do this with Visual C++ v4.0 and it is giving me an INTERNAL 
COMPILER ERROR.  I thought that this was legal syntax, but am not certain.
Thanks in advance for your help.



[ comp.std.c++ is moderated.  To submit articles: Try just posting with your
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu
]
Re: Namespaces within class definition???
#3546
Author: Steve Clamage
Date: Wed, 28 Feb 1996 21:14
33 lines
2034 bytes
In article ejv@nnrp1.news.primenet.com, kj7bg@primenet.com (Bob White) writes:

>Assuming that the "string" class is properly defined in namespace "std", is it 
>legal to do the following:

>class xyz : public std::string {
>}

>I am trying to do this with Visual C++ v4.0 and it is giving me an INTERNAL 
>COMPILER ERROR.  I thought that this was legal syntax, but am not certain.
>Thanks in advance for your help.

Yes, it's valid. Sounds like growing pains regarding a new language feature.

Try this as a workaround:

	using std::string;
	class xyz : public string { ...	};

The difference is that std::string is now placed in the current scope 
as "string", which might collide with other names in the program.
Ideally, you will abandon "string" as a user identifier because it is
the name of a standard class. Using "string" for other purposes
will be confusing and make future maintenance more difficult.
---
Steve Clamage, stephen.clamage@eng.sun.com
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your 
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu 
]
Re: Namespaces within class definition???
#3548
Author: Bob White
Date: Thu, 29 Feb 1996 06:23
52 lines
2733 bytes
Thanks for the fast response.  I guess Microsoft has a bug which I will let 
them know about.  I tried the following and it seems to work:

typedef	std::string XyzString;
class xyz : public XyzString { }

So I will use it until Borland and Microsoft allow me the more 
straight forward way.  Also, I am using the "string" class as defined by one 
version of the C++ standard which was put in the "std" namespace.  I thought
this was what the current standard required!   Maybe that's what I get for
thinking.  Anyway, thanks for the help!

[Moderator's note: remainder of article contains only quoted text. -fjh.]

In article <4h2ajf$l69@engnews1.Eng.Sun.COM>, clamage@Eng.Sun.COM says...
>
>In article ejv@nnrp1.news.primenet.com, kj7bg@primenet.com (Bob White) 
writes:
>
>>Assuming that the "string" class is properly defined in namespace "std", is 
it 
>>legal to do the following:
>
>>class xyz : public std::string {
>>}
>
>>I am trying to do this with Visual C++ v4.0 and it is giving me an INTERNAL 
>>COMPILER ERROR.  I thought that this was legal syntax, but am not certain.
>>Thanks in advance for your help.
>
>Yes, it's valid. Sounds like growing pains regarding a new language feature.
>
>Try this as a workaround:
>
>        using std::string;
>        class xyz : public string { ... };
>
>The difference is that std::string is now placed in the current scope 
>as "string", which might collide with other names in the program.
>Ideally, you will abandon "string" as a user identifier because it is
>the name of a standard class. Using "string" for other purposes
>will be confusing and make future maintenance more difficult.
>---
>Steve Clamage, stephen.clamage@eng.sun.com

---
[ To submit articles: try just posting with your news-reader.
                      If that fails, use mailto:std-c++@ncar.ucar.edu
  FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html
  Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu.
]
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads