Answer the question
In order to leave comments, you need to log in
How to bind the call of view elements to one activity or fragment?
I created FirstFragment and SecondFragment, I added a button to each, in the code, in SecondFragment I can call a button belonging to FirstFragment, and do anything with it, but there will be an error when the application starts. How can I make it so that I can only access those view elements in the code that are written in the called layout in the fragment? That is, if I write in FirstFragment, then only fragment_first layout elements will be available.
Answer the question
In order to leave comments, you need to log in
Private and protected is when the object hides that it is inherited from the student. From the outside, neither the fact of inheritance nor paternal fields is visible.
class Father {};
class Son : private Father {};
int main()
{
Son son;
Father& q = son;
}
#include <iostream>
class Callback {
public:
virtual void act(int x) = 0;
};
void generateFibonacci(int n, Callback& callback) {
int x1 = 0, x2 = 1;
for (int i = 0; i < n; ++i) {
callback.act(x2);
int x3 = x1 + x2;
x1 = x2;
x2 = x3;
}
}
class FileWriter : private Callback {
public:
FileWriter(std::ostream& aOs, int aN) : os(aOs), n(aN) {}
void run() { generateFibonacci(n, *this); }
private:
std::ostream& os;
const int n;
void act(int x) override { os << x << std::endl; }
};
using namespace std;
int main()
{
FileWriter wri(std::cerr, 10);
wri.run();
}
Everything is simple here. public means that everyone will know that student1 inherited from student, student's public methods will be visible to the outside.
protected means that only student1 and its descendants know it. private means that only student1 knows about this inheritance.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question