class Pointer {
private:
    int &x;
public:
    Pointer(int &y) : x(y) {}
    int getT() { return x; }
};
int main()
{
    int w = 40;
    Pointer test(w);
    std::cout << &test <<' ' << &w;
}
What is the significance of the int &x declaration in the class definition? I understand that the int &y passed as a parameter for the constructor is the value passed by reference, but what about int &x as this type of declaration is showing me an error inside the main() function?
Aucun commentaire:
Enregistrer un commentaire