0

I was following the example, but doesn't work, how can I fix this? error msg:

 

error LNK2019: unresolved external symbol "public: void __thiscall CWin::show_member(void)" (?show_member@CWin@@QAEXXZ) referenced in function _wmain c:...\TEST_DOMAIN_MODULE.obj

 

error LNK1120: 1 unresolved externals c:...\TEST_DOMAIN_MODULE.exe 1

// A_DOMAIN_MODULE.h

#pragma once
#include <iostream>
using namespace std;

class CWin 
{
private:
    char id;
    int width, height;

public:     
    CWin(char i,int w,int h):id(i),width(w),height(h) {}
    void show_member(void);
};


// A_DOMAIN_MODULE.cpp

#include "stdafx.h"
#include "A_DOMAIN_MODULE.h"

void CWin::show_member(void)
{
    cout << "Window " << id << ": ";
    cout << "width=" << width << ", height=" << height << endl;
}


// TEST_DOMAIN_MODULE.cpp

#include "stdafx.h"
#include "../A_DOMAIN_MODULE/A_DOMAIN_MODULE.h"

int main()
{
    CWin win1('A',50,40);
    win1.show_member();
    system("pause");
    return 0;
}
DaveG
  • 491
  • 1
  • 6
  • 19
  • I viewed it but still don't understand what's wrong with my program, in "main" function the "show_member()" definition goes to cpp file and declaration goes to header file, it seems all right but don't work – DaveG Jul 19 '18 at 14:08
  • 1
    I'd guess the problem is with your Visual Studio project setup. Check if `.cpp` file is in it and if it gets linked. – Yksisarvinen Jul 19 '18 at 14:26
  • A_DOMAIN_MODULE.h and A_DOMAIN_MODULE.cpp were auto generated, and if I declared "show_member()" in both, it were said "already has a body", so I guess they are linked – DaveG Jul 19 '18 at 14:30

0 Answers0