0

I'm trying to write a basic static class to Trigonometry utility in c++ for Cinder.

This is my main file:

#include "cinder/app/App.h"
#include "cinder/app/RendererGl.h"
#include "cinder/gl/gl.h"

//#include "MyStaticClass.h" //this simple include doesn't work...
#include "C:\Users\ALEX\Cinder Projects\LearnLinkage\vc2013\MyStaticClass.h"// so I have to use this stupid absolut path...

using namespace ci;
using namespace ci::app;
using namespace std;

class LearnLinkageApp : public App {
  public:
    void mouseDown( MouseEvent event ) override;
};

void LearnLinkageApp::mouseDown( MouseEvent event )
{
    MyStaticClass::MyStaticFunction();
}


CINDER_APP( LearnLinkageApp, RendererGl )

This is my static class file :

MyStaticClass.h

#pragma once
static class MyStaticClass
{
public:
    MyStaticClass();
    ~MyStaticClass();
    static void MyStaticFunction();
};

MyStaticClass.cpp

#include "MyStaticClass.h"


MyStaticClass::MyStaticClass()
{
}


MyStaticClass::~MyStaticClass()
{
}

static void MyStaticFunction(){

}

I've got this message error : Error 4 error LNK2019: unresolved external symbol "public: static void __cdecl MyStaticClass::MyStaticFunction(void)" (?MyStaticFunction@MyStaticClass@@SAXXZ) referenced in function "public: virtual void __thiscall LearnLinkageApp::mouseDown(class cinder::app::MouseEvent)" (?mouseDown@LearnLinkageApp@@UAEXVMouseEvent@app@cinder@@@Z) C:\Users\ALEX\Cinder Projects\LearnLinkage\vc2013\LearnLinkageApp.obj LearnLinkage

I made some researches about this https://en.wikipedia.org/wiki/Translation_unit_%28programming%29 and this https://en.wikipedia.org/wiki/One_Definition_Rule

the problem seems to be a static function get unresolved external symbol , can you tell me more about this ? and is it theorically possible to call a static function inside a virtual function in cpp ??

Thanks for your support

sachaamm
  • 139
  • 2
  • 13
  • 1
    _" and is it theorically possible to call a static function inside a virtual function in cpp ??"_ Sure it is. You're on the wrong track diagnosing your error. – πάντα ῥεῖ Jan 08 '16 at 02:01
  • 1
    Yes it is possible. Suspect it is your build instructions giving problems. - Also: why the tag spam, suire you are using "cinder", but it isn't relevant to the bit giving you problems.. – John3136 Jan 08 '16 at 02:01
  • 1
    You need to define the member function, not a similarly named free function; the member's full name is `MyStaticClass::MyStaticFunction`. (And "static" means completely different things when used with a member function and when used with a free function. The details of the differences aren't suited for the comment format.) – molbdnilo Jan 08 '16 at 02:11
  • 1
    Classes can't really be static, though they may contain static members, and you may declare static instances. – Joel Cornett Jan 08 '16 at 02:15
  • Thanks everybody for your answers ! The problem was just as molbdnilo explained , it was because I didn't defined my function with the namespace of my static class, so the compiler wasn"t able to link it – sachaamm Jan 08 '16 at 02:27

0 Answers0