0
#include<iostream>

using namespace std;

class Print;

class Class{
    Print * p;
    public:
    void foo(){p -> print();}
};
 
class Print{
public:
    void print(){
        cout << "PRINT\n";
    }
};


int main(){

}

Подскажите почему я могу использовать метод print? как его тогда вызвать если мне нужно определение класса Print только после определения класса Class?

1 ответ 1

0

Примерно так:

#include<iostream>

using namespace std;

class Print;

class Class{
    Print * p;
    public:
    void foo();
};
 
class Print{
public:
    void print(){
        cout << "PRINT\n";
    }
};

void Class::foo(){p -> print();}

int main(){

}

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.