0

i am trying to get GameAPI pointer so

that my substruct test can use it.

Code:

struct GameAPI 
{
    static GameAPI* Ptr;

    GameAPI()
    {
        Ptr = this;
    }

    struct
    {
        void func()
        {
            printf("%p",&Ptr);
        }
    }test;
};

ERROR: unresolved external symbol "public: static struct GameAPI * GameAPI::Ptr"

  • 1
    What is your specific question about C++? – Sam Varshavchik Jul 21 '20 at 23:19
  • Does this answer your question? [c++ copy struct unresolved link](https://stackoverflow.com/questions/20948548/c-copy-struct-unresolved-link) – MikeCAT Jul 21 '20 at 23:25
  • 2
    Keep an eye on `printf("%p",&Ptr);`. The results may surprise you. Note: This looks dangerous. Perhaps you are headed in the direction of [a singleton](https://stackoverflow.com/a/1008289/4581301). Not that singleton can't also be dangerous, but this has [a lot of extra blow-up potential](https://ideone.com/VTp32o). – user4581301 Jul 21 '20 at 23:46

1 Answers1

2

You've only declared Ptr but you forgot to define it outside the GameAPI definition.

Add:

GameAPI* GameAPI::Ptr = nullptr; // or another suitable value
Ted Lyngmo
  • 93,841
  • 5
  • 60
  • 108