[Tuxcpprogramming] Not everything inherited with inheritance??

Mark Phillips mark at austrics.com.au
Thu Jul 19 16:57:31 UTC 2001


Hi,

It would seem that when you inherit a class, not
everything gets passed on.  Consider the following
example:


#include <iostream>
#include <string>
using namespace std;

class tstTy: public string {
 public:
  void printIt() {
    cout<<*this<<endl;
  }
};

main(int argc, char **argv) {
  string str="grape";
  tstTy tst="banana";

  tst.printIt();
}


When I try to compile it, it complains with:

tst_main.cpp: In function `int main(int, char **)':
tst_main.cpp:16: conversion from `const char[7]' to non-scalar type
`tstTy' requested

So it seems that whereas the string type can happily
convert standard character strings to string type,
tstTy, which is inherited from string, can't!!!

Why is this so???

And what can I do about it?

Thanks,

Mark.





More information about the tuxCPProgramming mailing list