I'm a very beginner in c++. first I used cmd only for c programs. but with c++ I have some problems.
I searched for this question on Google, and actually found the same problem, but nobody knows why and how to fix it. They have some solution, but it's not fixing the source of the problem. The solution is: to use Microsoft Visual Studio, create a project and add files in it. It works well, but I used to work in gVim and used cmd to compile programs, and I like that. But now, i have to move to Visual studio... Is there any solution with it?
So this is 3 files: first - CourseBook.h
#include <string>
using namespace std;
class CourseBook
{
public:
CourseBook(string);
void setCourseBookName(string);
string getCourseName();
void displayMessage();
private:
string courseBookName;
};
2-nd is CourseBook.cpp:
#include <iostream>
#include "CourseBook.h"
using namespace std;
CourseBook::CourseBook(string name)
{
setCourseBookName(name);
}
void CourseBook::setCourseBookName(string name)
{
courseBookName=name;
}
string CourseBook::getCourseName()
{
return courseBookName;
}
void CourseBook::displayMessage()
{
cout<<"The course book name is "<<getCourseName()
<<endl;
}
and 3-rd is ggg.cpp:
#include <iostream>
#include "CourseBook.h"
using namespace std;
int main()
{
CourseBook myCourseBook("HeLLO MATE");
myCourseBook.displayMessage();
}
The error is: C:\Users\Луна\Desktop\go>g++ -o go ggg.cpp c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:\Users\0EAF~1\AppData\Local\Temp\ccQ2VInH.o:ggg.cpp:(.text+0x48): undefined reference to
CourseBook::CourseBook(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)' c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:\Users\0EAF~1\AppData\Local\Temp\ccQ2VInH.o:ggg.cpp:(.text+0x69): undefined reference to
CourseBook::displayMessage()' collect2.exe: error: ld returned 1 exit statusC:\Users\Луна\Desktop\go>