How to print static variable in struct with a method using C++

1 Answer

0 votes
#include <iostream>

struct Example {
    static int x, y;
    
    static void Print() {
        std::cout << x << ", " << y << "\n";
    }
};

int Example::x;
int Example::y;

int main() {
    Example ex;
    
    Example::x = 98;
    Example::y = 7;

    Example::Print();
}




/*
run:

98, 7

*/

 



answered Jan 29, 2023 by avibootz

Related questions

1 answer 109 views
1 answer 168 views
1 answer 165 views
1 answer 176 views
1 answer 161 views
1 answer 216 views
...