0

I use Atom as my IDE for c++, a normal hello world project works fine and I can use a class if i defines everything in the header file and doesn't do anything in the cpp file.. I have tried to take working code from others but it still doesn't work so I'm pretty sure that it's something that compiles incorrectly or something, please help!!! Heres the error:

/tmp/ccXIaLmD.o: In function `main':
Main.cpp:(.text+0x82): undefined reference to `Name::Name(std::__cxx11::basic_string<char, std::char_traits<char>,  std::allocator<char> >, std::__cxx11::basic_string<char,  std::char_traits<char>, std::allocator<char> >)'
Main.cpp:(.text+0xce): undefined reference to `Name::getName[abi:cxx11]()'
collect2: error: ld returned 1 exit status

Main.cpp

#include <iostream>
#include "Name.h"

using namespace std;

int main(){
  Name name("Johannes", "Gustafsson");
  cout << name.getName() << endl;
}

Name.h

#ifndef NAME_H
#define NAME_H

#include <string>
using namespace std;

class Name{
private:
  string forName;
  string lastName;

public:
  Name();
  Name(string pforName, string plastName);
  void setName(string pforName, string plastName);
  string getName();
};

#endif

Name.cpp

#include "Name.h"
#include <string>

using namespace std;

Name::Name(){
  forName = "For name";
  lastName = "Last name";
}

Name::Name(string pforName, string plastName){
  forName = pforName;
  lastName = plastName;
}

void Name::setName(string pforName, string plastName){
  forName = pforName;
  lastName = plastName;
}

string Name::getName(){
  return forName + " " + lastName;
}
Johannes
  • 1
  • 2

0 Answers0