LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-11-2005, 06:09 AM   #1
kadissie
LQ Newbie
 
Registered: Jul 2003
Location: UK
Distribution: Fedora 5, Knoppix, Ubuntu
Posts: 27

Rep: Reputation: 15
Two-stage name lookup in C++


I recently upgraded my Linux system, which resulted in my version of gcc going from 3.3.2 to 3.4.2. Some header files that were working under 3.3.2 are now failing to compile in 3.4.2 due to the correction of a name lookup bug in the older compiler. A full description of the situation is given here.

I'm now wondering what the most effective remedy to this is. It is suggested in the above link that one of two solutions are used: either insert a this-> before each base class name, or explicitly bring the base class name into scope with Base<T>:: .

Both of the these solutions are, to be honest, ugly. U-uh-glee. Beautifully clear code is now sprinkled with thises and thats or double colons. So being the adventurer I am, I tried
Code:
template <typename T> struct Base { int i; };
template <typename T> struct Derived : public Base<T> {
         int get_i() { using namespace Base<T>; return i; }
       };
But gcc returned an error
Quote:
error: expected identifier
error: expected `;'
error: declaration does not declare anything
Undaunted, I thought "Well, it's more work for me, but perhaps I can bring each name into scope at the start of each templated member function of the derived class". So I change the derived class to read
Code:
template <typename T> struct Derived : public Base<T> {
         int get_i() { using Base<T>::i; return i; }
       };
which gives me the error
Quote:
error: `Base<T>' is not a namespace
This is strange, since "inline" scope resolution like Base<T>::i works. Why shouldn't a using-declaration work?

Anyone have any suggestions to unclutter my code? Is it supposed to be this difficult to use non-dependent names from templated base classes in derived classes?

R.

Last edited by kadissie; 01-11-2005 at 06:13 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Traceroute, Ping, Domain Name Server (DNS) Lookup, WHOIS, and DNS Records Lookup netoknet General 1 05-09-2005 03:43 AM
Half of my applications are broken. I am using Gentoo stage 1 on 3 nptl (stage 1.5) dragonslay Linux - Games 3 04-01-2005 05:23 PM
Gentoo: Stage 1, Stage 2, or Stage 3 skorpi0wn Linux - Distributions 3 03-01-2005 07:47 PM
Could not uncompress second stage ramdisk SidA Mandriva 10 06-15-2004 06:41 AM
second stage install? nlghtcrawler Linux - Software 1 12-12-2003 02:36 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:01 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration