0

Ok, so I have a struct defined as thus:

#ifndef __STRUCTS_H__
#define __STRUCTS_H__

struct counts {
    int views = 0;
    int inits = 0;
};

#endif

I have a class that is going to have entirely static methods and variables that are accesable by all classes.

#ifndef __HOLDER_H__
#define __HOLDER_H__

#include "Structs.h"

class Holder
{
public:
    static counts menus;

    Holder() {
        menus = counts();
    }
};

#endif

And so I tried to acess this method and the compiler spits out the error "Undefined reference to Holder::menus"

Here is the segment that triggers this (HelloWorldScene.cpp)

#include "HelloWorldScene.h"
#include "SimpleAudioEngine.h"
#include "Holder.h"
#include "Structs.h"

USING_NS_CC;

HelloWorld::HelloWorld(void)
{
    //Constructor
    Debug::crashLog("**__Menu Deinit__**");
    //SUDO Missing stuff
    Holder::menus.inits -= 1;
}

Why is it having issues?

J.Doe
  • 1,502
  • 13
  • 47
  • Possible duplicate of [What is an undefined reference/unresolved external symbol error and how do I fix it?](http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – Tas May 30 '16 at 01:26
  • In particular, [this part](http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix/12574407#12574407) or simply do a search for `static` – Tas May 30 '16 at 01:27

1 Answers1

0

in your Holder implementation file you need this:

counts Holder::menus;

if you don't have Holder.cpp file, (and you don't want one) you can put it directly into in HelloWorldScene.cpp.

Alastair Brown
  • 1,598
  • 8
  • 12
  • Now it says "extra qualification 'Holder::' on member 'menus' [-fpermissive] – J.Doe May 30 '16 at 01:29
  • Sorry, I think that was the `static` I accidently added - try the latest revision. – Alastair Brown May 30 '16 at 01:31
  • It needs to be static. I compiled it without the keyword static and now not only is their the "Extra qualification" error, but also "invalid use of non-static data member" – J.Doe May 30 '16 at 01:32