LinuxQuestions.org
Visit the LQ Articles and Editorials section
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 12-11-2002, 12:59 AM   #1
cybercop12us
Member
 
Registered: Aug 2001
Posts: 60

Rep: Reputation: 15
problem in template function. compiles in vc++ not in gcc 3.0.4


hi all,

The following sample code compiles and executes perfectly in vc++. But gcc is

parse error before `::' token in the line
std::string test=b::c::d; in the following program

I think its not correct to complain since itz a template kind of thing
and the compiler is not going to reserve any space for the template function since i have not implemented it.

can anybody throw light on this.

thanks in advance,
harish

eg.cpp

#include<iostream>
using namespace std;
namespace IMP{
template<typename a,typename b> void
fun(){

std::string test=b::c::d;
cout<<"works";
}
}

void main(){

cout<<"just for test";
}
 
Old 12-11-2002, 03:28 PM   #2
crabboy
Moderator
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,823

Rep: Reputation: 120Reputation: 120
Looks like it should compile to me...

It compiled fine an AIX/RS6000 with the xlC compiler.
 
Old 12-11-2002, 05:54 PM   #3
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,978
Blog Entries: 11

Rep: Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879
funny one ...

When I try to compile it with gcc 2.95.3 or 3.2
I get:
eg.cpp: In function `void IMP::fun()':
eg.cpp:5: parse error before `='

Including the headers from STLPort
(with both compilers) I get this:
eg.cpp: In function `void IMP::fun()':
eg.cpp:5: parse error before `::'

Not that I quite understood what you were trying to do :}
But changing b::c::d to a::b compiles fine? :)
Using STLPort, that is ... without STLPort I still keep
getting
eg.cpp:5: parse error before `='
 
Old 12-11-2002, 10:34 PM   #4
crabboy
Moderator
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,823

Rep: Reputation: 120Reputation: 120
I was getting parse error before '=' before adding #include <string>
 
Old 12-12-2002, 01:04 AM   #5
cybercop12us
Member
 
Registered: Aug 2001
Posts: 60

Original Poster
Rep: Reputation: 15
friends, thanks for your responses. I did not get any parse error before =. my only doubt was why the compiler is not behaving in standard way with respect to std::string test=b::c::d;
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
g++ compiles but not gcc senthilpr_in Linux - Software 10 08-29-2005 02:20 PM
C code compiles on windows, but not with gcc MDBlueIce Programming 6 05-23-2005 04:33 PM
gcc 3.4.2 and template issue ahwkong Programming 1 04-16-2005 01:18 PM
function prototypes in template class' (c++) qwijibow Programming 4 12-13-2004 09:34 AM
gcc, segmentation fault, though compiles... scratch09 Programming 5 11-20-2004 05:11 PM


All times are GMT -5. The time now is 01:16 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration