I want to use a function from my Page class but I do not want to inherit from it. Is there another way I can use theonPage(vector<string> vec) function in my element and elementX class without using inheritance? Would association Work? I was thinking that.
Code is below:
class Page
{
string str;
vector<string>::iterator it;
void onPage(vector<string>vec);
};
class element
{
Page p;
};
class elementX : public element
{
};
Declare it
public, so foreign classes can access it.(you can use
public,privateandprotectedto control access to class members, make sure to read them all up.privateis the default for classes).