g++ compilation problems




Hello, I didn't want to trouble the good people in c.l.c++, as these
are more of a compiler question than a language one.

Issue 1.

This code:
-------------------------------------
#include <vector>

typedef vector<unsigned char> bytes;
int main()
{
bytes data;
exit(0);
}
-------------------------------------
compiles fine with g++ v2.95.3, but with v3.4.3 (the most recent
version I have to hand) it fails with

xxx.cc:3: error: expected init-declarator before '<' token
xxx.cc:3: error: expected `,' or `;' before '<' token

Can someone please explain what the problem is here?

===========================================
Issue 2.

This code:
-------------------------------------
#include <iostream>
#include <string>
using namespace std;
class Base
{
public:
void f(string&) {cout << "Base::f()\n";}
};

class Derived : public Base
{
public:
using Base::f; // error here!
void f(char*) {cout << "Derived::f()\n";}
};

int main()
{
string myStr = "abc";
Derived obj;

obj.f(myStr);
}
-------------------------------------
this on is the other way round. It compiles and runs corectly using g+
+ v3.4.3, but with v2.95.3 I get:

xx.cc:15: cannot adjust access to `void Base::f(string &)' in `class
Derived'
xx.cc:14: because of local method `void Derived::f(char *)' with
same name

even though the function has a different signature.

I suspect my Issue 2 is an old compiler bug which has since been
fixed, but I don't understand what's happening in Issue 1.

Any advice welcome!

.



Relevant Pages

  • Re: [CodeGallery] MFC MD5 Calculator
    ... Then when they added types, internally, the compiler still thought they were int values, ... ANSI standard began to emerge that the language design ...
    (microsoft.public.vc.mfc)
  • Re: Syntax for union parameter
    ... Does that mean "main" is not an essential part of the language? ... However, people would disagree about which headers to consider special in this way, and it is easier to be consistent if they are treated as any other header file. ... using 'int' would be just too vague. ... However having them in the compiler *would* ...
    (comp.lang.c)
  • Re: First steps on overloading
    ... where the operand manipulation code is located, ... very many additions and changes to the language semantics. ... Allowing int + date, as well as date + int (although the former seems a bit ... compiler would reorder the operands. ...
    (comp.lang.misc)
  • Re: Property vs Variable of class
    ... It seems to complicate the program. ... private int _i; ... those functions don't mean anything special to the compiler in C++. ... Yes, it introduces yet another new concept to the language, but that new concept allows you to in a much simpler way implement the same thing that you should have been doing all along, in a way that makes that implementation more explicit both to you, the compiler, and other components within .NET. ...
    (microsoft.public.dotnet.framework)
  • Re: syslog-ng 3.5.3 installation on solaris10, i386
    ... configure:3612: checking for gcc ... configure:3908: checking whether the C compiler works ... | #ifdef YY_USE_CONST ... | * int a single C statement. ...
    (comp.unix.solaris)