1

I defined a header file as follows:

class MathFunUI {
  public:
      void mainMethod(void);
};

And the corresponding cpp file:

#include <iostream>
#include <stdio.h>
#include <conio.h>
#include <vector>

MathFunUI::mainMethod(void)
{
    //To DO
}

And I get an error like this:

|undefined reference to `MathFunUI::mainMethod()'|
||error: ld returned 1 exit status|
||=== Build failed: 2 error(s), 0 warning(s) (0 minute(s), 1 second(s)) ===|

I am not able to get what simple thing I am missing here?

PS: My main method if it can help;

#include "MathFunUI.h"

int main(void)
{
    MathFunUI MUI;
    MUI.mainMethod();
    return 0;
}
yobro97
  • 1,125
  • 8
  • 23
  • you forgot the return type in the definition... also you don't need (and probably shouldn't) specify that a function doesn't take arguments with `(void)` in C++ – UnholySheep Jul 02 '17 at 19:07
  • 1
    How are you building? Calling a compiler directly? Using an IDE? Are you sure your *.cpp file is included? By the way, you're missing the `void` return type on the function definition, but that would be a compiler error, not a linker error. – aschepler Jul 02 '17 at 19:07
  • @UnholySheep.....I was actually trying to be a bit formal by adding `void` there....didn't know it would be a problem though. – yobro97 Jul 02 '17 at 19:09
  • @aschepler.....included the `main()` method in `PS`. – yobro97 Jul 02 '17 at 19:10
  • @yobro97 That's just more code, not a compiler command or IDE usage. – aschepler Jul 02 '17 at 19:14
  • Guys the problem is solved. I used `#pragma once`. I was using another `class` which was used by `MathFunUI`. There were multiple inclusions of the same header files. Thank you! – yobro97 Jul 03 '17 at 21:14

0 Answers0