There are two classes, one is the parent, the other is the heir.

**Base.h** class Derived;//предв. объявление сlass Base { public: void pic(); } **Derived.h** #include"Base.h" сlass Derived:public Base { public: static const char* str_to_bckgrnd; } const char* Derived::str_to_bckgrnd="Images/environment/background/lev_1/33.png"; **Base_func_implementation.h** #include"Base.h" void Base::pic() { i_a=ImageAdd(str_to_bckgrnd); } 

I want to use a string variable in the base class that I declare in the heir. Thought to make in the file with the base class the preliminary class declaration of the successor, did not help.

these are the mistakes

 IntelliSense: identifier "str_to_bckgrnd" is undefined 'str_to_bckgrnd' : undeclared identifier 

How can I read a variable from an heir class? unless of course it can)

    2 answers 2

    Simply declare a virtual method in the base class that returns the information you need and implement it in the heir.

     **Base.h** сlass Base { public: void pic(); protected: const char* get_something() = 0; } **Derived.h** #include"Base.h" сlass Derived:public Base { public: static const char* str_to_bckgrnd; private: const char* get_something() { return str_to_bckgrnd; } } const char* Derived::str_to_bckgrnd="Images/environment/background/lev_1/33.png"; **Base_func_implementation.h** #include"Base.h" void Base::pic() { i_a=ImageAdd(get_something()); } 
    • Oh, you beat me. - VladD
    • Thank you) and for what function get_something () in the base class to declare protected, and in the inherited to write as private? - Dexter384
    • @Dexter384, read in the book about access specifiers, and you can do it differently, depending on what you want to achieve. For your example, there are enough such qualifiers. Well, "If you are given a comprehensive answer, mark it as correct (click on the check mark next to the selected answer)." - dzhioev

    I do not know, I do not know ... such a perversion will go? :

     #include <iostream> using namespace std; class parent{ public: char *suda; }A; class derived : public parent{ public: char stroka; void iderived(){ stroka='X'; A.suda=&stroka; cout<<*A.suda<<endl; } }D; void main() { D.iderived(); char a=*A.suda; printf("%c \n",a); }