|
Home > Archive > Unix Programming > July 2007 > g++ compilation problems
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
g++ compilation problems
|
|
| keith@bytebrothers.co.uk 2007-07-20, 7:20 am |
|
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!
| |
| Ian Collins 2007-07-20, 7:20 am |
| keith@bytebrothers.co.uk wrote:
> 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;
typedef std::vector<unsigned char> bytes;
Old gcc was very slack in its use of std::
>
> 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!
>
Don't use old compilers!
--
Ian Collins.
| |
| keith@bytebrothers.co.uk 2007-07-20, 7:20 am |
| On 20 Jul, 12:00, Ian Collins <ian-n...@hotmail.com> wrote:
> ke...@bytebrothers.co.uk wrote:
>
>
> typedef std::vector<unsigned char> bytes;
>
> Old gcc was very slack in its use of std::
Bingo. Thank you, thank you!
(as you can probably tell, I'm slowly making the 'paradigm shift' to C+
+ after 20 years of C, and stuff like that floors me every time)
|
|
|
|
|