The following code compiles fine. but when goes to linking,
it shows following error
Undefined symbols for architecture x86_64:
    "derived::counter", referenced from:
     derived::getAddressCounter()      in main.cpp.o 
     ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
I suspect there is something wrong with the static. but not sure why. Because once I take out the static, the code links fine. But how does static plays any role in this code?
#include <iostream>
#include <string>
struct base_result { };
struct result : public base_result {
    int a;
    std::string b;
};
struct base {
    static base_result counter;
};
struct derived: public base {
    static result counter;
    result * getAddressCounter(){
        counter.a = 10; 
        counter.b = "haha";
        return &counter;
    }   
 };
int main (){ 
    derived d;
    result * ptr;
    ptr = d.getAddressCounter();
    ptr->a = 20; 
    ptr->b = "baba";
    std::cout << ptr->a << std::endl;
    std::cout << ptr->b << std::endl;
    return 0;
}
 
     
     
    