Build error with header file

Asked

Viewed 27 times

0

I cannot create classes with header file. When I create the file . h and create the implementation of member functions in the file . cpp gives error when compiling. I thought it was me, so I went to the site Microsoft an example they gave. It was an error in my compiler, but in an online compiler it worked. inserir a descrição da imagem aqui

// my_program.cpp
#include "my_class.h"

using namespace N;

int main()
{
    my_class mc;
    mc.do_something();
    return 0;
}

// my_class.cpp
#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_class.h
namespace N
{
    class my_class
    {
    public:
        void do_something();
    };

}
  • Looks like link error. Place the entire error message. Ideally it would display the compiler call, which parameters are being passed to it.

  • On my computer ran smoothly on Windows in Visual Studio 2019 with CL19.27. The code looks exactly like this?

  • Yes. This example I copied directly from the Microsoft website. I thought I was doing something wrong, but it’s my own computer. I apologize for the delay in responding.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.