Reputation: 23
I have a problem when compiling my main class.
//main.cpp
#include "Division.h"
int main() {
Division Root;
}
Here is my Division.h
//Division.h
#pragma once
#include <string>
#include <windows.h>
class Division {
public:
Division();
Division(std::string Name, std::string PhoneNumber, std::string Description, Division& Parent);
private:
UUID GUID;
std::string Name;
std::string PhoneNumber;
std::string Description;
Division* Parent;
};
And here is my Division.cpp
#include <string>
#include <windows.h>
using namespace std;
class Division {
public:
Division() {};
Division(string Name, string PhoneNumber, string Description, Division &Parent) {
UuidCreate(&GUID);
this->Name = Name;
this->PhoneNumber = PhoneNumber;
this->Description = Description;
this->Parent = &Parent;
}
private:
UUID GUID;
string Name;
string PhoneNumber;
string Description;
Division* Parent;
};
In the main class I just want to create an empty Division object using the first constructor. Why am I getting the Linker error? What am I doing wrong?
Upvotes: 0
Views: 242
Reputation: 36092
You have declared Division twice, both in header and cpp file.
You should only have the declaration in the header.
In the .cpp file include the header and define the methods
Division::Division() {}
Division::Division(std::string name, std::string phoneNumber, std::string description, Division &parent) {
UuidCreate(&GUID);
Name = name;
PhoneNumber = phoneNumber;
Description = description;
Parent = &parent;
}
It is also good to use other names for member variables than parameters.
Upvotes: 2