Trying to print out the elements of a linked list (with multiple classes)

So I have an issue that has been bugging me for days now. I have 3 classes : Film, Csalad, Dokumentum. These 3 classes describe movie/film categories, basically “Csalad” is family friendly films, “Dokumentum” is a document film. And everything else is in the Film class. The Film class is the parent class, which has a few a private char* typed small “arrays” (like: char* cim[25+1], that’s for the title). And it’s child classes has some special private variables like: char* eletkor[2+1] for the Csalad class. The problem is that I have succesfully read my necassery data from a txt file, into a syngly linked list(in the txt file every line has a special type with that I can easly decide which film is in which category, and make them into the right class, for example: if something is a simple film I make for them in the Film constructor, if it’s a family friendly film I make them in the Csalad constructor). But I have problems printing them onto the screen. My main goal is to go through my linked list and basically print every single data onto the screen. It sounds easy, but it’s not, cause I can’t find a method that can both print out the title for example (which is located in the Film class, and intherited by every single other class like Csalad) and can print out Csalad’s private variable eletkor.

Can you guys help me?

Here’s some code:

“kov” means next in English.

Film.h

#include <cstring>
#include <iostream>
class Film{
private:
    char cim[25+1], kiadas[4+1], idotartam[4+1], tema[25+1];
    int hossz;

public:
    Film* kov;

    //Konstruktor   
    Film(char* dcim, char* dkiadas, char* didotartam, char* dtema, int dhossz){
        strcpy(cim, dcim);
        strcpy(kiadas, dkiadas);
        strcpy(idotartam, didotartam);
        strcpy(tema, dtema);
        kov = NULL;
        hossz = dhossz;
    }

    //Masolo konstruktor
    Film(const Film& masolando){
        strcpy(this->cim, masolando.cim);
        strcpy(this->kiadas, masolando.kiadas);
        strcpy(this->idotartam, masolando.idotartam);
        strcpy(this->tema, masolando.tema);
        this->kov = masolando.kov;
    }

    //Getterek
    char* getCim(){
        return cim;
    }

    int getHossz(){
        return hossz;
    }
};

Csalad.h

#include "Film.h"

class Csalad : public Film{
private:
    char eletkor[2+1];

public:
    Csalad(char* dcim, char* dkiadas, char* didotartam, char* dtema, char* deletkor, int dhossz):Film(dcim, dkiadas, didotartam, dtema, dhossz){
        strcpy(eletkor, deletkor);
    }

    char* getEletkor(){
        return eletkor;
    }

    std::ostream& print(std::ostream& os){
        os << "Cs.Cim: " << getCim() << " " << "Eletkor: " << getEletkor();
        return os;
    }
};

Dokumentum.h looks similar to Csalad.h it doesn’t really matter at this point.

Those ostreams were my pathetic tries in the main funciton. I make the linked list via a function called “beolvas” and it gives out a Film* type pointer. So my main looks something like this:

int main(){
    Film* eleje = NULL;
    eleje = beolvas(eleje);
    if(eleje == NULL){
        cout << "Hiba a beolvasással" << endl;
        return 1;
    }
}

For the printing part, I have been trying to make something like this:

for(*SOME KIND OF A TYPE OR SOMETHING* mozgo = eleje; mozgo != NULL; mozgo = mozgo->kov){
    printing...
}

If you have any further questions, feel free to ask.

Answer

A virtual print() function solved the problem, I didn’t tought that it would be that easy. I over thought it.