I'm starting with C++ and I'm trying to create a class program, however, when I try to run it appears the error: C++: Undefined reference to 'NameSpace::Class::Constructor. The code is shown below:
Header for ClassA:
//ClassA.h
#ifndef CLASSA_H
#define CLASSA_H
#include <string>
namespace ClassANameSpace
{
class ClassA
{
private:
std::string attribute1;
double attribute2;
public:
ClassA();
ClassA(std::string pAttribute1, double pAttribute2);
void setClassA(std::string pAttribute1, double pAttribute2);
std::string getAttribute1() { return attribute1; }
double getAttribute2() { return attribute2; }
};
}
#endif
Class A:
//ClassA.cpp
#include "ClassA.h"
using namespace ClassANameSpace;
ClassA::ClassA()
{
}
ClassA::ClassA(std::string pAttribute1, double pAttribute2)
{
setClassA(pAttribute1, pAttribute2);
}
void ClassA::setClassA(std::string pAttribute1, double pAttribute2)
{
attribute1 = pAttribute1;
attribute2 = pAttribute2;
}
Main:
// main.cpp
#include <iostream>
#include "ClassA.h"
using namespace std;
using namespace ClassANameSpace;
int main(int argc, char const *argv[])
{
ClassA classA ("string", 1.0);
return 0;
}
When I try to run it appears: undefined reference to `ClassANameSpace::ClassA::ClassA(std::__cxx11::basic_string<char, std::char_traits, std::allocator >, double)'
Someone can guide me to undestand what is going on?