Methodenzugriff auf Vaterklasse



  • Hallo,

    ich habe 2 Klassen (Fortbewegungsmittel und Flugzeug)

    Dabei erbt Flugzeug von Fortbewegungsmittel.

    In beiden Klassen habe ich eine Methode "string sag_was()" implementiert.

    Fortbewegungsmittel

    #include <iostream>
    using namespace std;
    
    class Fortbewegungsmittel
    {
    protected:
    	float x,y;
    public:
    
    	Fortbewegungsmittel(float x_,float y_):x(x_),y(y_){}
    
    	string sag_was() 
    	{
    		ostringstream s1;
    		s1<<"Ich befinde mich bei" << "x:" << x << " y: " <<y;
    
    		string s;
    		s+=s1.str();
    		return s;
    
    	}
    
    	void set_all(float x_, float y_) 
    	{
    		x=x_;
    		y=y_;
    	}
    
    	void set_x(float x_) 
    	{
    		x=x_;
    	}
    
    	void set_y(float y_)
    	{
    		y=y_;
    	}
    
    	float get_x() 
    	{
    		return x;
    	}
    
    	float get_y() 
    	{
    		return y;
    	}
    };
    

    Flugzeug

    #include <sstream>
    #include <string>
    #include "Fortbewegungsmittel.h"
    
    class Flugzeug:public Fortbewegungsmittel
    {
    	float hoehe;
    public:
    	Flugzeug(float x_, float y_,float hoehe_):Fortbewegungsmittel(x_,y_),hoehe(hoehe_) 
    	{
    
    	}
    
    	string sag_was() 
    	{
    		ostringstream s1;
    		//s1 <<   sag_was() Methode der Klasse Fortbewegungsmittel
    		s1 << "hoehe: " << hoehe;
    
    		string s;
    		s+=s1.str();
    		return s;
    	}
    
    	void set_hoehe(float hoehe_) 
    	{
    		hoehe=hoehe_;
    	}
    
    	float get_hoehe()
    	{
    		return hoehe;
    	}
    
    };
    

    Wie kann ich nun in der Methode "string sag_was()" in Flugzeug die Methode "string sag_was()" der Klasse Fortbewegungsmittel aufrufen?
    (In Java geht das mit super. aber irgendwie kennt c++ super. nicht)



  • Fortbewegungsmittel::sag_was()
    

Anmelden zum Antworten