public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Strangeness with G++ 3.0.2 and typedefs
@ 2002-01-08 10:44 Ken Shiring
  0 siblings, 0 replies; 3+ messages in thread
From: Ken Shiring @ 2002-01-08 10:44 UTC (permalink / raw)
  To: gcc-help

Hello all, I am hoping that someone on this list can help me with the 
following problem.  The following code snippet will compile properly 
under G++ 2.95.2 :

#include <stdio.h>
#include <vector>

typedef vector<int> vecint_t;

int main(int argc, char** argv)
{
	return(0);
}


The problem lies in the typedef of the template (the main function is 
just there so the compiler actually has something to compile). Under G++ 
3.0.2, G++ says :

ktest.C:4: syntax error before `;' token
make: *** [obj/ktest.o] Error 1


Why is G++ 3.0.2 complaining?  This is legitmate ISO C++ is it not?

-- 
Ken Shiring

IBM Corporation
PEPS Embedded PowerPC design group
Research Triangle Park, NC

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Strangeness with G++ 3.0.2 and typedefs
@ 2002-01-08 11:05 Ken Shiring
  0 siblings, 0 replies; 3+ messages in thread
From: Ken Shiring @ 2002-01-08 11:05 UTC (permalink / raw)
  To: gcc-help

Oops, I just realized what I did wrong.  I was perusing the other issues 
on this list, and I realized I now need a "using namespace std;" to be 
truly ISO compliant. Problem solved, no need to reply.

-- 
Ken Shiring

IBM Corporation
PEPS Embedded PowerPC design group
Research Triangle Park, NC

^ permalink raw reply	[flat|nested] 3+ messages in thread

* RE: Strangeness with G++ 3.0.2 and typedefs
       [not found] <616BE6A276E3714788D2AC35C40CD18D2C5086@whale.softwire.co.uk>
@ 2002-01-08 11:02 ` Rupert Wood
  0 siblings, 0 replies; 3+ messages in thread
From: Rupert Wood @ 2002-01-08 11:02 UTC (permalink / raw)
  To: 'Ken Shiring'; +Cc: gcc-help

Ken Shiring wrote:

> typedef vector<int> vecint_t;
:
> Why is G++ 3.0.2 complaining?  This is legitmate ISO C++ is it not?

No, it's not. 'vector' should exist only in the 'std' namespace and not
the global namespace: i.e. you must qualify 'vector' with 'std::'

    #include <vector>
    typedef std::vector<int> vecint_t;

or import std::vector into the global namespace:

    #include <vector>
    using std::vector;
    typedef vector<int> vecint_t;

or import the whole std namespace:

    #include <vector>
    using namespace std;
    typedef vector<int> vecint_t;

GCC 2.95.x's standard C++ library was less fussy and defined STL types
in both the 'std' namespace and the global namespace.

IMO, you should use the first if you use 'vector' in a header file (so
as to avoid polluting the namespace of an including file) and either the
first or second in source files depending how much 'vector' is used. The
third solution is perhaps the simplest but often regarded as poor style:
it is less precise that the other two.

Hope that helps,
Rupert.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2002-01-08 19:05 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-01-08 10:44 Strangeness with G++ 3.0.2 and typedefs Ken Shiring
     [not found] <616BE6A276E3714788D2AC35C40CD18D2C5086@whale.softwire.co.uk>
2002-01-08 11:02 ` Rupert Wood
2002-01-08 11:05 Ken Shiring

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).