How to initialize class variable in constructor with C++

1 Answer

0 votes
#include <iostream>

class Example {
public:
    float x, y;
    
    Example() {
        x = 0.0f;
        y = 0.0f;
    }
    
    void Print() {
        std::cout << x << ", " << y << "\n";
    }
};

int main() {
    Example ex;
    
    ex.Print();
    
}




/*
run:

0, 0

*/

 



answered Jan 29, 2023 by avibootz

Related questions

1 answer 262 views
2 answers 277 views
2 answers 262 views
262 views asked Jan 29, 2023 by avibootz
1 answer 266 views
1 answer 230 views
1 answer 265 views
...