Online-Skater
Erfahrenes Mitglied
Habe ein Problem mit dem Vererben, bin noch blutiger Anfänger 
Hier das Problem
Meldung:
:: === SuperInt, Debug ===
D:\PROJECTS\C++\OOP\SuperInt\SuperInt.cpp:21: error: no match for 'operator[]' in '*(SuperInt*)this[k]'
:: === Build finished: 1 errors, 0 warnings ===
Dieser Operator solle eigentlich vererbt werden von vector in der vector.cpp
Woran könnte das liegen ?

C++:
// Hauptklasse in vector.h
#include <cassert>
#include <iostream>
using namespace std;
#ifndef VECTOR_H
#define VECTOR_H
class Vector
{
int *p;
const int i1;
int num;
public:
// Operatoren für Vectoren
const Vector& operator= (const Vector&);
bool operator== (const Vector&) const;
bool operator!= (const Vector&) const;
const Vector& operator+= (const Vector&);
Vector operator+ (const Vector&) const;
const Vector& operator+= (int);
Vector operator+ (int) const;
const Vector& operator-= (const Vector&);
Vector operator- (const Vector&) const;
const Vector& operator-= (int);
Vector operator- (int) const;
const Vector& operator++ (); // prefix ++v
Vector operator++ (int); // postfix v++
const Vector& operator-- (); // prefix --v
Vector operator-- (int); // postfix v--
const Vector& operator*= (const Vector&);
Vector operator* (const Vector&) const;
const Vector& operator/= (const Vector&);
Vector operator/ (const Vector&) const;
const Vector& operator&= (const Vector&);
Vector operator& (const Vector&) const;
const Vector& operator&= (const int&);
Vector operator& (const int&) const;
friend Vector operator& (const int&,const Vector&); // other order
Vector operator- () const;
int& operator[] (int);
int operator[] (int) const;
Vector operator() (int,int);
friend ostream& operator<< (ostream&,const Vector&);
friend istream& operator>> (istream&,Vector&);
int operator^ (const Vector& v) const;
// Standardmemberfunktionen
Vector(int first_index=1, int number=0);
Vector(const Vector&);
~Vector() {delete[] p;}
int first() const { return i1; }
int last() const { return i1+num-1; }
int length() const { return num; }
int read(int);
void change(int,int);
};
#endif
C++:
// Abgeleitete Klasse in SuperInt.h
#include "vector.h"
#ifndef SUPERINT_H
#define SUPERINT_H
class SuperInt : protected Vector
{
SuperInt(bool neg,int len)
: Vector(0,len), negative(neg) {};
bool negative;
public:
SuperInt(long int n = 0);
Vector::length; // access control
int operator() (int) const; //gives digit no. k
SuperInt operator+ (const SuperInt&) const;
SuperInt operator- (const SuperInt&) const;
SuperInt operator* (const SuperInt&) const;
SuperInt operator* (int) const;
SuperInt operator/ (const SuperInt&) const;
SuperInt operator/ (int) const;
SuperInt operator- () const;
bool operator== (const SuperInt&) const;
bool operator!= (const SuperInt&) const;
bool operator< (const SuperInt&) const;
bool operator> (const SuperInt&) const;
bool operator<= (const SuperInt&) const;
bool operator>= (const SuperInt&) const;
friend istream& operator>> (istream&, SuperInt);
friend ostream& operator<< (ostream&, const SuperInt);
};
#endif
C++:
#include "SuperInt.h"
#include <cmath>
// Hilfsfkt. für Anzahl der Stellen
int num_digit(long int n)
{
if (n==0)
return 1;
else
return (int)log10(labs(n)) + 1;
}
// Default- and type conversion constructor
SuperInt::SuperInt(long int n)
: Vector(0, num_digit(n))
{
negative = (n<0);
n = labs(n); // Absolutwert
for (int k=0; k<length(); k++)
{
(*this)[k] = n % 10; // Save the digits <----FEHLER
n /= 10; // backwards
}
}
:: === SuperInt, Debug ===
D:\PROJECTS\C++\OOP\SuperInt\SuperInt.cpp:21: error: no match for 'operator[]' in '*(SuperInt*)this[k]'
:: === Build finished: 1 errors, 0 warnings ===
Dieser Operator solle eigentlich vererbt werden von vector in der vector.cpp
C++:
// Ausschnitt
// Overloading the index operator
int& Vector::operator[] (int i)
{
assert(i >= i1 and i <= last());
return p[i-i1]; // return a reference
}
int Vector::operator[] (int i) const
{
assert(i >= i1 and i <= last());
return p[i-i1]; // return a copy
}
Woran könnte das liegen ?
