Welcome to HBH! If you have tried to register and didn't get a verification email, please using the following link to resend the verification email.

C++ call class from a class


ghost's Avatar
0 0

can i call from class1 a fucnction which is in class2? if yes, how? i've tryed it but it isn't worked.


ghost's Avatar
0 0

thanks


ghost's Avatar
0 0

so, i have this source, i've set up the friends but it's not working:

{
    friend class sys;
    private:
     string input;

     void handle(string input)
     {
         if (input == "help")
         {
         //condition block
         }
         if (input == "cls")
         {
             sys::clear(); //trying to call the clear function in the class sys
             command();
         }
         if (input == "ls" && sbinactive) //working with sbin() function;
         {
         }
         else
         {
             command();
         }
     }
    public:
     void command()
     {
         cout << "[root@localhost /sbin]# ";
         getline(cin, input);
         handle(input);
     }
};

class sys
{
    friend class commands;
    private:
    public:

    void pause()
    {
        cout << "Press ENTER to continue ... ";
        cin.get();
    }
    void clear()
    {
        system("cls");
    }
    void endline()
    {
        cout << "\n";
    }
    void initialize()
    {
        //inicializace vectoru se soubory pro sbin
        //plnim vector daty
        sbin(); //volam fci sbin();
    }
};

commands com1;
sys sys1;```
the calling is still not working. what is wrong? thanks.

ynori7's Avatar
Future Emperor of Earth
0 0

couldnt you just #include class2 at the top of class1?


ghost's Avatar
0 0

it is big project and i need this classess for better orientation. of course i can include it in headers, but classess will be maybe better.