This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

strings, templates, and multible inheritance


Hi,

The following piece of code defines a template for multible inheritance.

If I use the template construct with classes A and B,
the program compiles fine. 
However, if I use a string in the template, the
compiler exits with an error (see below).

test1105str.cc: In method
`C<basic_string<char,string_char_traits<char>,__default_alloc_template<false,0>
>,b>::C<string, b>(class
basic_string<char,string_char_traits<char>,__default_alloc_template<false,0>
>)':
test1105str.cc:30: type `string' is not a base type for type
`C<basic_string<char,string_char_traits<char>,__default_alloc_template<false,0>
>,b>'

Note that there is a distinction in the message between 
type `string'
and
basic_string<char,string_char_traits<char>,__default_alloc_template<false,0> 
>
which (I think) ought to be the same.

On gcc version egcs-2.91.16 980328 (gcc-2.8.0 release)
the program compiles fine in both cases.


----- 
#include <string>

class a
{
public:
  int i;
  a(void)
    : i(0)
    {}
  a(int j)
    :i(j)
    {}
};


class b
{
public:
  char c;
  b(void): c('\0'){}
  b(char j):c(j){}
};


template <class A, class B>
class C: public A, public B
{
public:
 C(A a)
   : A(a),B()
    {}

};

typedef C<a,b> aggregate1;
typedef C<string,b> aggregate2;

int main(void)
{
  string s("Hallo");
  aggregate1 ag1(5); // This works ok
  aggregate2 ag2(s); // this gives a compile time error
  return 0;
}

--
>g++ -v
Reading specs from
/home/gewaltig/opt/lib/gcc-lib/i686-pc-linux-gnulibc1/egcs-2.91.28/specs
gcc version egcs-2.91.28 19980508 (gcc2 ss-980502 experimental)
one:/home/gewaltig/synod2/sli/tests>g++ -v test1105str.cc
Reading specs from
/home/gewaltig/opt/lib/gcc-lib/i686-pc-linux-gnulibc1/egcs-2.91.28/specs
gcc version egcs-2.91.28 19980508 (gcc2 ss-980502 experimental)
 /home/gewaltig/opt/lib/gcc-lib/i686-pc-linux-gnulibc1/egcs-2.91.28/cpp
-lang-c++ -v -undef -D__GNUC__=2 -D_ 
_GNUG__=2 -D__cplusplus -D__GNUC_MINOR__=91 -D__ELF__ -Dunix -Dlinux
-D__ELF__ -D__unix__ -D__linux__ -D__un 
ix -D__linux -Asystem(posix) -D__EXCEPTIONS -Di386 -Asystem(unix)
-Acpu(i386) -Amachine(i386) -D__pentiumpro 
__ -D__i686__ -D__i386__ -Asystem(unix) -Acpu(i386) -Amachine(i386)
-D__pentiumpro__ -D__i686__ test1105str. 
cc /tmp/cca30752.ii
GNU CPP version egcs-2.91.28 19980508 (gcc2 ss-980502 experimental) (i386
Linux/ELF)
#include "..." search starts here:
#include <...> search starts here:
 /home/gewaltig/opt/include/g++
 /usr/local/include
 /home/gewaltig/opt/i686-pc-linux-gnulibc1/include

/home/gewaltig/opt/lib/gcc-lib/i686-pc-linux-gnulibc1/egcs-2.91.28/include
 /usr/include
End of search list.

/home/gewaltig/opt/lib/gcc-lib/i686-pc-linux-gnulibc1/egcs-2.91.28/cc1plus
/tmp/cca30752.ii -quiet -dumpbas 
e test1105str.cc -version -o /tmp/cca30752.s
GNU C++ version egcs-2.91.28 19980508 (gcc2 ss-980502 experimental)
(i686-pc-linux-gnulibc1) compiled by GNU 
 C version egcs-2.91.28 19980508 (gcc2 ss-980502 experimental).
test1105str.cc: In method
`C<basic_string<char,string_char_traits<char>,__default_alloc_template<false,0>
>, 
b>::C<string, b>(class
basic_string<char,string_char_traits<char>,__default_alloc_template<false,0>
>)':
test1105str.cc:30: type `string' is not a base type for type
`C<basic_string<char,string_char_traits<char>,_ 
_default_alloc_template<false,0> >,b>'
 
_________________________________________________________________
Dipl. Phys. Marc-Oliver Gewaltig
Institut fuer Biologie III
Albert-Ludwigs-University                                       
Hansastr. 9a,                       Tel: +49-761-203-9550
D-79104 Freiburg i.Br.              Fax: +49-761-203-2745
Germany             



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]