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: 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: It Pays to Enrich Your C Skills
    ... Check if you can score a perfect 10 (without using a compiler). ... int main{ ... struct bitfield { ... out if it is a negative integer constant or a constant expression ...
    (comp.lang.c.moderated)
  • OT: Re: Perl Peeves
    ... I see the result of a test being used as an int. ... the compiler just assumed you knew what you were doing ... introduced to the language later, so void * was unheard of in most code. ... This didn't mean bool was special, declaring it just signaled to the ...
    (comp.lang.perl.misc)
  • Re: identity...... Was: The wisdom of the object mentors
    ... And what about construction of int? ... I construct all objects in the same manner.....(like a C++ compiler ... in mid air...I need a language, some axioms and some rules of ...
    (comp.object)
  • Re: OT: Re: Perl Peeves
    ... when I see the result of a test being used as an int. ... compiler just assumed you knew what you were doing and would ... This didn't mean bool was special, declaring it just signaled to the ... What "normalization of bool results is built into the compiler"? ...
    (comp.lang.perl.misc)