0

I'm dealing with oop and cannot understand what is wrong. When i try to compile code i get next messsage: undefined reference to `N::my_class::do_something()'. Code is from microsoft: https://learn.microsoft.com/en-us/cpp/cpp/header-files-cpp?view=msvc-160
my_class.h file:

namespace N
{
    class my_class
    {
    public:
        void do_something();
    };

}

my_class.cpp file:

#include "my_class.h" // header in local directory
#include <iostream> // header in standard library

using namespace N;
using namespace std;

void my_class::do_something()
{
    cout << "Doing something!" << endl;
}

my_program.cpp file:

#include "my_class.h"

using namespace N;

int main()
{
    my_class mc;
    mc.do_something();
    return 0;
}
Pablo
  • 9
  • 1

1 Answers1

1

Your code works for me on g++ 8.4.0.

using namespace N; might not enough to declare member function in N for your compiler. Try to specify the namespace either inline or using a namespace scope in your cpp file.

EDIT: most likely problem. my_class.cpp is not compiled or linked. Check your compile parameters.

log0
  • 10,489
  • 4
  • 28
  • 62