[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference turris::c_plus_plus

Title:C++
Notice:Read 1.* and use keywords (e.g. SHOW KEY/FULL KIT_CXX_VAX_VMS)
Moderator:DECCXX::AMARTIN
Created:Fri Nov 06 1987
Last Modified:Thu Jun 05 1997
Last Successful Update:Fri Jun 06 1997
Number of topics:3604
Total number of notes:18242

3572.0. "something about not using namespace and now failing ..." by BACHUS::SABLON () Wed May 14 1997 17:41

T.RTitleUserPersonal
Name
DateLines
3572.1this is a user error that is now being caught in V5.6DECC::J_WARDWed May 14 1997 18:3036
/*
The behaviour you are seeing has nothing to
do with namespaces. Namespaces are not used
in the V5.6 version of the standard library.

The code is illegal and is now correctly diagnosed in
V5.6. There's a class variable called map and so if
you want to refer to the global map when you're inside 
the class scope you have to use :: to distinguish it.

So the user either needs to change the name of the
variable map or needs to change:

	typedef map<int, int, less<int>, allocator<pair <const int, int> > > 
				Map_String_String;

to:

	typedef ::map<int, int, less<int>, allocator<pair <const int, int> > > 
				Map_String_String;

Below is a small example showing the situation. 

FYI, if you make map a non-templatized class then you'll see
that V5.5 used to complain in that situation.
*/

// This was not diagnosed in V5.5, it is diagnosed in V5.6
template <class T>
class map {};

struct MyClass {
	typedef map<int> foo; // oops, need to put :: to refer to global  
	int map;
};

3572.2more problem about mapBACHUS::SABLONFri May 16 1997 16:4454
3572.3I think this shows a compiler bug...DECC::J_WARDFri May 16 1997 18:1154
I think what you (they?) are seeing is
a compiler bug. It works correctly in our
6.0 (under development) compiler.

I will post it in our internal bug tracking
system. Below is a small example showing
the bug and also a possible workaround.

// This is a small example showing a 
// bug with scoping and typedefs
// I think this should compile cleanly

struct map {
	typedef int itype;
};

struct MyClass
{
        typedef ::map map_type;
        void f() { map_type::itype i;}
};

main() {;}

// The only workaround I can think of is to create a typedef
// inside MyClass corresponding to each typedef in map that 
// they are using, i.e.:

#include <map>

class MyClass
{
    public:
        typedef int             MyType;
        typedef ::map<int, int, less<int>, allocator<pair <const int, int> > >
                                Map_String_String;

	// add this for each typedef you need
        typedef ::map<int, int, less<int>, allocator<pair <const int, int> >
>::const_iterator
                                Map_String_String_const_iterator;

    private:
        MyType                  myAttribute;
        Map_String_String       map;

        void f(void){
		// change this
                Map_String_String_const_iterator i = map.find(2);
        };
};

Judy
3572.4some more from the customerBACHUS::SABLONTue May 20 1997 15:3234
3572.5closedDECCXX::MITCHELLTue May 20 1997 20:013
Since this is fixed in V6.0 and since this is no longer an
issue to the customer, we don't plan any further action
on this problem report.