I know this seems to be a common problem. However, I seem to be following all of the standard practices and guidelines for header files except for include guards which I don't think would hinder compilation. The linker errors described only occur when CustomerInformation.h is included into CPlusPlusTraining.cpp which contains the main method.
This is one source I used for C++ file organization information: http://www.umich.edu/~eecs381/handouts/CppHeaderFileGuidelines.pdf
Here is my header
class CustomerInformation {
public: CustomerInformation();
public: char InformationRequest();
};
Source
#include "stdafx.h"
#include <iostream>
#include <string>
#include "CustomerInformation.h"
using namespace std;
char InformationRequest() {
string name;
string lastName;
int age;
cout << "Please input your first and last name then your age: \n";
cin >> name >> lastName >> age;
cout << "Customer Information: " << name + " " << lastName + " " << age << "\n";
char correction;
cout << "Is all of this information correct? If it is Enter 'Y' if not Enter 'N' \n";
cin >> correction;
if (correction == 'N') {
cout << "Please Enter your information again: \n";
InformationRequest();
}
return correction;
}`
And my include into CPlusPlusTraining.cpp
#include "stdafx.h"
#include <iostream>
#include <string>
#include "CustomerInformation.h"
using namespace std;
Both the header file and source file have the same name. The header file ends in .h while the source file ends in .cpp. However I am getting numerous linker errors when compiling. What is the problem here? I'll save repetitive code inclusion for another day. Thanks.
How I call the method in my file with Main in it
CustomerInformation CI = CustomerInformation::CustomerInformation();
//information request
CI.InformationRequest(); //Not type safe for input
Error Details:
Build started: Project: CPlusPlusTraining, Configuration: Debug Win32 ------ 1> CPlusPlusTraining.cpp //File with Main 1>CPlusPlusTraining.obj : error LNK2019: unresolved external symbol "public: __thiscall CustomerInformation::CustomerInformation(void)" (??0CustomerInformation@@QAE@XZ) referenced in function _wmain 1>CPlusPlusTraining.obj : error LNK2019: unresolved external symbol "public: char __thiscall CustomerInformation::InformationRequest(void)" (?InformationRequest@CustomerInformation@@QAEDXZ) referenced in function _wmain 1>C:\Users\Gordlo_2\documents\visual studio 2013\Projects\CPlusPlusTraining\Debug\CPlusPlusTraining.exe : fatal error LNK1120: 2 unresolved externals ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
g++ main.cpp InfoRequest.cpp
– Fantastic Mr Foxcpp
in your linking stage. – Fantastic Mr Fox