Reputation: 7
I have a main class in which Im trying to call on a function to create the menu but I keep getting this error:
error LNK2019: unresolved external symbol "public: static int __cdecl Controller::menu(void)" (?menu@Controller@@SAHXZ) referenced in function _main
This is my main class.
#include "Main.h"
using namespace std;
int main ()
{
Control:: menu();
return 0;
}
this is the Main.h
#pragma once
#include "Control.h"
class Main:
{
public:
Main(void);
~Main(void);
int main();
};
the Control.h:
#pragma once
#include <iostream>
class Control
{
public:
Control(void);
~Control(void);
static int menu ();
};
and finally the control cpp file:
#include "Control.h"
using namespace std;
static int menu ()
{
bunch of menu code
return 0;
}
I think it's something simple but I just cant figure it out. I tried removing static as well as changing the function to a void function, but neither worked.
Upvotes: 0
Views: 176
Reputation: 3346
The static function with its prototype should be this way.
int Control :: menu()
{
//bunch of menu code
return 0 ;
}
While you are implementing the class in another file, you have to use the class name with scope resolution operator as well.
You are also having an extra colon at the end of class Main
resulting in syntax error.
Upvotes: 2
Reputation: 258558
static int menu ()
{
bunch of menu code
return 0;
}
should be
int Control::menu ()
{
bunch of menu code
return 0;
}
That's the proper way of defining members.
Upvotes: 3