0

I am trying to reteach myself on classes and such, but am having a hard time compiling the code. Below are my header, implementation and main codes. When I try to compile, I get:

LNK2019 unresolved external symbol "public: __thiscall artType::artType(void)" (??0artType@@QAE@XZ) referenced in function _main

I realize that this is an over-done question, but I have spent several days trying to get this (retyping it, researching, reading documentation, pulling hair out) and I wish not to spend too much more time on this stupid error.

Thanks in advance for the help,

Nathan

Code: Header (art.h)

#pragma once
class artType
{
public:
    int x;
    int get();
    artType();
};

Implementation file (art.cpp)

#include "art.h"
artType::get()
{
    return x;
}
artType::artType()
{
    x = 2;
}

Main code (Ov1.cpp)

#include "stdafx.h"
#include <iostream>
#include "art.h"
using namespace std;

int main()
{
    artType a;
    int num = 0;
    num = a.get();
    cout << num << endl;
    return 0;
}
  • You *do* build with the `art.cpp` source? It's in your project as a source file? – Some programmer dude Aug 30 '15 at 21:42
  • Since your code is correct, I would say the most likely error is that you are not linking the implementation file, that is it's not included in your 'project'. – john Aug 30 '15 at 21:42
  • SImple test, move the code from art.cpp to Ov1.cpp and see if it works then. I'm guessing this is the first program you've written with more than one cpp file. – john Aug 30 '15 at 21:44
  • @JoachimPileborg, I believe that I did. Is there a special thing I need to do to add it as a source file other than have it in the same folder? – Nathan Fredrickson Aug 30 '15 at 21:50
  • @john Not my first, just first in a while :) And it did run with the code from the implementation file in main – Nathan Fredrickson Aug 30 '15 at 21:52
  • I figured out my problem. The panel for adding it to source was auto hidden on the sidebar. Opened that, it looked familiar, added the file and it worked. Sorry for wasting your time haha – Nathan Fredrickson Aug 30 '15 at 21:55
  • Yes, just putting the multiple source files in the same folder on the disk doesn't add them to the actual project. You need to actually add them to the projects source folder in Visual Studio. It will be much easier if you create the files from inside the IDE as then they would be members of the project automatically. – Some programmer dude Aug 30 '15 at 21:55

0 Answers0