473,396 Members | 1,749 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Undefined end() in extended map template

Hi all,

I have this template which does not compile with "Compaq C++ V6.5-004
for OpenVMS Alpha V7.3-1" and Comeau C/C++ 4.3.3. This looks like
there must really be error in the code:

#include <map>

template <class Key, class T, class Compare = std::less<Key>,
class Allocator = std::allocator<std::pair<const Key, T> > >
class map_of_objects : public std::map<Key, T, Compare, Allocator>
{
typedef typename std::map<Key, T, Compare, Allocator> parent_tpl;

public:
typedef Key key_type;
typedef typename Allocator::size_type size_type;
typedef typename parent_tpl::iterator iterator;

size_type erase(const key_type& x)
{
iterator i = *find(x);
if (i != end())
{
delete *i;
}
parent_tpl::erase(x);
}
};

It compiles fine in Borland C++ 5.5 and Compaq C++ V6.2-048 for
OpenVMS Alpha V7.3. I do not understand why end() is undefined and
find() is defined. There must be something I really miss. This problem
can be solved by using "this->end()" or "using parent_tpl end;".
However, I still do not understand what I am doing wrong.

Ondrej
Jul 22 '05 #1
1 1517
Ondrej Brablc wrote in
news:b8**************************@posting.google.c om:
Hi all,

I have this template which does not compile with "Compaq C++ V6.5-004
for OpenVMS Alpha V7.3-1" and Comeau C/C++ 4.3.3. This looks like
there must really be error in the code:

#include <map>

template <class Key, class T, class Compare = std::less<Key>,
class Allocator = std::allocator<std::pair<const Key, T> > >
class map_of_objects : public std::map<Key, T, Compare, Allocator>
{
typedef typename std::map<Key, T, Compare, Allocator> parent_tpl;

public:
typedef Key key_type;
typedef typename Allocator::size_type size_type;
typedef typename parent_tpl::iterator iterator;

size_type erase(const key_type& x)
{
iterator i = *find(x);
This should be:

iterator i = this->find(x);

if (i != end())
if (i != this->end())
or
if (i != parent_tpl::end())
{
delete *i;
}
parent_tpl::erase(x);
}
};

It compiles fine in Borland C++ 5.5 and Compaq C++ V6.2-048 for
OpenVMS Alpha V7.3. I do not understand why end() is undefined and
find() is defined. There must be something I really miss. This problem
can be solved by using "this->end()" or "using parent_tpl end;".
However, I still do not understand what I am doing wrong.


You're not telling the compiler that end() is a dependant name.
The compilers that compile this are not *fully* conforming with the
C++ Standard.

A "dependant name" is a name (identifier) that is dependant on 1 or
more template paramiters. In this case since std::map<Key, T, Compare,
Allocator> (i.e. parent_tpl) depends on template paramiters, then its
members are dependant on template paramiters.

The conforming compilers implement 2-phase name lookup. When they first
encounter your template declaration's they check them, including looking
up all the identifiers that they encounter. The reason an error wasn't
given for find( x ) is its paramiter 'x', since 'x' is of dependant type
then clearly the find in 'find( x )' is a dependant name, so the compiler
doesn't try to look it up.

Consider:

template < typename T >
stuct X
{
void dependant_name();
};

template < typename T >
stuct X< T * > // partial specialization
{
void dependant_name();
};

template < typename T >
struct Y : X< T >
{
void non_pointers()
{
dependant_name();
}
};

Also the following is included later (at global scope):

void dependant_name();

Then:

int main()
{
Y< int * > y;

y.non_pointers();
}

Note that above, in main(), the call y.non_pointers() is an error,
but the non-conforming compilers compile it and call the global
dependant_name(), which has *nothing* to do with the templates X<>
and Y<>.

The conforming compilers should complain that the identifier
dependant_name in Y<>::non_pointers() hasn't been declared.

HTH (and wasn't to long winded).

Rob.
--
http://www.victim-prime.dsl.pipex.com/
Jul 22 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Vincent Lefevre | last post by:
Hello, The XPath 1.0 recommendation says: A number represents a floating-point number. A number can have any double-precision 64-bit format IEEE 754 value . These include a special...
3
by: Steven T. Hatton | last post by:
Scroll to the bottom and read the last part first. I've been trying very diligently to 'modularize' the code from TC++PL3E found here: http://www.research.att.com/~bs/matrix.c I keep getting...
9
by: blueblueblue2005 | last post by:
Here is a very simple template example, whenever I seperate the header and implementation file, I got "undefined reference to member function error. and if I put the header and definition in one...
2
by: B_Love | last post by:
Hey! When trying to compile the code for a ordered vector class I get the following error: undefined reference to `WinMain@16' Anyone have any idea what I might be doing wrong? I've been...
1
by: Alan Johnson | last post by:
From the standard 5.3.5/5: "If the object being deleted has incomplete class type at the point of deletion and the complete class has a non-trivial destructor or a deallocation function, the...
3
by: s.z.s | last post by:
Hi! I hope the solution to that is not too stupid... I've got three files: <snip test_main.cc> #include"test.hh" int main(void) { A<inta1; a1.saywhat();
1
by: yamitmehta | last post by:
When I compile to code using g++arm of VxWorks 5.5 and put it on my board i get the follwing undefined symbols:- Cpool and Csingleton are template classes. CPool has the static member...
4
by: Hora | last post by:
Hi Guys I'm reading Andrew Koenig and Barbara E. Moo 's book, Accelerated C++. It's the best works for newbie I ever read. The way the authors introduce the language is very interesting. In...
8
by: shaielinna | last post by:
<? ob_start(); session_start(); require('../includes/inc.php'); require('../includes/settings.php'); include("../includes/dbconnect.php");?> <?php // requires the class require...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.