473,406 Members | 2,378 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,406 software developers and data experts.

Porting from g++ 2.95/3.2 to g++ 4.01 template problem

Dear all,

When porting some code from g++ 2.95/3.2 to g++ 4.01 we
encountered some difficulties with the following construction.
The code is known to compile on g++ 2.95 and g++ 3.2.2.

This is a condensed test case based on our code.
We believe this is a general c++ standard compliance problem,
and not a g++ problem or bug.

However, we have been unable to find out how this should be done!
The compilation stops at the definition of current_item_,
the compiler does not manage to resolve that line.

(Ideally the code is going to be used to make a slightly specialized
list class from the standard c++ list class)

If anyone can point us in the right directions, we would be
immensely grateful.

- Gunnar
----------------------------------------------------------
MeListTest.h:
----------------------------------------------------------
#ifndef MELISTTEST_H
#define MELISTTEST_H

#include <list>

using namespace std;

template <typename Item>
class ListTest : public list<Item>
{
protected:
list<Item>::iterator current_item_;

public:

ListTest() {}
ListTest(const ListTest& src) : list<Item>(src),
current_item_(src.current_item_) {}
virtual ~ListTest() {}

list<Item>::iterator getIterator(int index)
{ return current_item; }
};

#endif

-----------------------------------------------------
main.cpp
-----------------------------------------------------

#include "MeListTest.h"

int main()
{
ListTest<int> mylist;
}

Sep 15 '05 #1
2 1544
weatherman wrote:
Dear all,

When porting some code from g++ 2.95/3.2 to g++ 4.01 we
encountered some difficulties with the following construction.
The code is known to compile on g++ 2.95 and g++ 3.2.2.

This is a condensed test case based on our code.
We believe this is a general c++ standard compliance problem,
and not a g++ problem or bug.

However, we have been unable to find out how this should be done!
The compilation stops at the definition of current_item_,
the compiler does not manage to resolve that line.

(Ideally the code is going to be used to make a slightly specialized
list class from the standard c++ list class)

If anyone can point us in the right directions, we would be
immensely grateful.

- Gunnar
----------------------------------------------------------
MeListTest.h:
----------------------------------------------------------
#ifndef MELISTTEST_H
#define MELISTTEST_H

#include <list>

using namespace std;
bad idea in headers.

template <typename Item>
class ListTest : public list<Item>
{
protected:
list<Item>::iterator current_item_;
typename list<Item>::iterator current_item_;
public:

ListTest() {}
ListTest(const ListTest& src) : list<Item>(src),
current_item_(src.current_item_) {}
virtual ~ListTest() {}

list<Item>::iterator getIterator(int index)
typename list<Item>::iterator getIterator(int index)
{ return current_item; }
{ return current_item_; }
};

#endif

-----------------------------------------------------
main.cpp
-----------------------------------------------------

#include "MeListTest.h"

int main()
{
ListTest<int> mylist;
}

Within templates, the compiler does not make assumptions about what kind of
entity an identifier like list<Item>::iterator refers to. This can only be
deduced once Item is known. Thus, you have to tell the compiler that
iterator is a type and not a member function or member object.
Best

Kai-Uwe Bux
Sep 15 '05 #2
Thanks. The medicine works!

-- gunnar

Sep 15 '05 #3

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

Similar topics

0
by: Diederick Huijbers | last post by:
Dear reader, For the last three years I'm using the template parser of PHPlib with a lot of pleasure. I think this is still the best mechanism for seperating PHP-code and HTML related code. Of...
2
by: Michele | last post by:
Slowly embracing C++ and as such I've got C code (see snippet below) I'd like to essentially port to C++. The idea is to 1. Use a TEMPLATE class to handle the 'double' buffering scheme...
5
by: Kenton Groombridge | last post by:
Hi, I previous posted this in a gcc and g++ groups since that is the compiler I am working with, but I didn't get any response. Hopefully these are the right groups for this question. I am...
0
by: Olaf Petzold | last post by:
Hi, the following code fragment doesn't compile: ----8<------ #include <iostream> template<class T, std::size_t Sz>
2
by: Jay | last post by:
Hi, Can anyone tell me why the following code doesn't work on 7.1? It's been ok with previous versions. The error given by the linker is: rtwnd.obj : error LNK2019: unresolved external symbol...
3
by: slarti | last post by:
My VS6 version used #include <fstream.h> which for VS.net I had to change to #include <fstream> using namespace std; Now I get a compiler error :
1
by: siva.isukapalli | last post by:
Hi, We are involved in a porting project (from VC++ 6.0 to .Net VC++ 7.1). ** NOT C# or VB..NET. We have a custom app wizard written in 6.0. This basically creates a project with a set of...
4
by: Chuck Chopp | last post by:
I have an application that I originally built using Visual Studio .NET 2003 as native C++ . This application includes a template class that was derived from the string class that's part of the C++...
47
by: =?Utf-8?B?ZW1hdmlzdQ==?= | last post by:
Dear guys, I'm in trouble having to port my project from C++Builder6 to VisualC++. Has anyone of you idea if there are any tools to help my doing this job? My current project is widely using VCL...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.