LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 04-23-2004, 12:38 AM   #1
ashwinipahuja
Member
 
Registered: Mar 2004
Posts: 79

Rep: Reputation: 15
Question Typedef Problem in GCC in Linux


Hi all
I am working on C++ project on KDE in Linux.
I have the following piece of code.

#include<iostream>
using namespace std;
class xyz
{
public:
typedef char i;
};
namespace First
{
template<class IMP,class DB>
class Floor
{
public:
typedef IMP database;
typedef DB::i view;
};
int main()
{
Floor<char,xyz> B;
}

This code works perfectly in Microsoft compiler.
But on GCC it gives error message - ::i is not a valid declarator.

If anyone has some idea then please Help!!
regards
Ashwini
 
Old 04-23-2004, 12:44 AM   #2
micxz
Senior Member
 
Registered: Sep 2002
Location: CA
Distribution: openSuSE, Cent OS, Slackware
Posts: 1,131

Rep: Reputation: 75
Chnage " typedef DB::i view;" to " typedef DB view;"

This is a guess' I'm not a programmer.
 
Old 04-23-2004, 09:50 AM   #3
dakensta
Member
 
Registered: Jun 2003
Location: SEUK
Distribution: Debian & OS X
Posts: 194

Rep: Reputation: 35
Hi, ashwinipahuja

Remember the last problem you had with typedefs ...
Code:
template <typename A, typename B, typename C , typename D >
class Myclass
{
public:
typedef typename D MyType;
};
Where you don't want typename because it is already explicit as a template parameter?

Good.

This time you need to use typename.

In your example, there is no way to know whether DB::i is this
Code:
class DB
{
int i;
}
... OR ...
Code:
class DB
{
typedef int i;
}
Therefore you need to tell the compiler that i is in fact a type and not a value using the typename keyword.

Here is a complete example:
Code:
template<typename A>
class AClass
{
public:
  typedef A value_type;   // NO typename KEYWORD

  value_type i;
};

template<typename B>
class BClass
{
public:
  typedef typename B::value_type val;  // WE NEED typename HERE

};

int main ()
{
  AClass<int> a;
  BClass<AClass<int> > b;

}

Last edited by dakensta; 04-23-2004 at 09:59 AM.
 
Old 04-23-2004, 10:02 AM   #4
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
Re: Typedef Problem in GCC in Linux

Quote:
Originally posted by ashwinipahuja
But on GCC it gives error message - ::i is not a valid declarator.
Not sure if this caused your problem, but also remember that to compile C++, you need compile with g++ instead of gcc.
 
Old 04-26-2004, 03:14 AM   #5
ashwinipahuja
Member
 
Registered: Mar 2004
Posts: 79

Original Poster
Rep: Reputation: 15
Thanx dakensta!!!!
It worked
Thanx everyone!!!
 
  


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
a question regarding typedef erikash Programming 1 11-10-2005 04:37 AM
typedef defines which type? kpachopoulos Programming 1 11-10-2005 02:46 AM
Can you help me with typedef? brownstone Programming 3 06-11-2004 10:09 AM
explanation on typedef naren Programming 5 03-09-2004 10:48 PM
sizeof my typedef... jhorvath Programming 7 10-11-2002 05:41 PM

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

All times are GMT -5. The time now is 06:09 AM.

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