I get this error is Visual Studio C++ :: "error LNK2019: unresolved external symbol" -
this question has answer here:
i see there no shortage of these on site, @ wits end figure out. simple program 3 file. when attempt compile program link error. 3 files show in solution explorer.
here output
1>------ build started: project: problem 2, configuration: debug win32 ------ 1>build started 5/13/2013 8:33:06 pm. 1>initializebuildstatus: 1> touching "debug\problem 2.unsuccessfulbuild". 1>clcompile: 1> main.cpp 1> dayofyear.cpp 1> generating code... 1>manifestresourcecompile: 1> outputs up-to-date. 1>main.obj : error lnk2019: unresolved external symbol "public: void __thiscall dayofyear::print(void)" (?print@dayofyear@@qaexxz) referenced in function _main 1>c:\users\digivision\desktop\school\cs-150-01\w11ch11\problem 2\debug\problem 2.exe : fatal error lnk1120: 1 unresolved externals 1> 1>build failed. 1> 1>time elapsed 00:00:01.72 ========== build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
here 3 files
main.cpp
#include <iostream> #include "dayofyear.h" using namespace std; int main() { int num; { cout << "enter number (-1 escape): "; cin >> num; if (num != -1) { dayofyear day(num); day.print(); } cout << endl; } while (num !=-1); cout << endl; return 0; }
dayofyear.cpp
#include "dayofyear.h" #include <iostream> using namespace std; int number; dayofyear::dayofyear(int n) { number = n; } void print() { const char * const month[12] = {"january","february","march","april","may","june", "july","august","september","october","november","december"}; if (number < 32) // jan cout << month[0] << " " << number; else if (number < 60) // feb cout << month[1] << " " << 60 - number; else if (number < 91) // mar cout << month[2] << " " << 91 - number; else if (number < 121) // apr cout << month[3] << " " << 121 - number; else if (number < 152) // may cout << month[4] << " " << 152 - number; else if (number < 182) // jun cout << month[5] << " " << 182 - number; else if (number < 213) // jul cout << month[6] << " " << 213 - number; else if (number < 244) // aug cout << month[7] << " " << 244 - number; else if (number < 274) // sep cout << month[8] << " " << 274 - number; else if (number < 305) // oct cout << month[9] << " " << 305 - number; else if (number < 335) // nov cout << month[10] << " " << 335 - number; else if (number < 366) // dec cout << month[11] << " " << 366 - number; }
dayofyear.h
#ifndef dayofyear_h #define dayofyear_h class dayofyear { private: int number; public: dayofyear() { number = 0; } dayofyear(int); void print(); }; #endif
definition of void print()
in dayofyear.cpp
should use ::
operator
void dayofyear::print() { //function body goes here }
otherwise, not interpreted member function of class dayofyear
.
Comments
Post a Comment