I'm trying to set up a basic class using std::string as a function type and a variable type, but using both gives me a segmentation fault. If I delete either the function or the variable, everything is fine. I'm sure I'm making a really stupid mistake! This is my code: main.cpp
#include <iostream>
#include <cstdlib>
#include <string>
#include "myclass.h"
int main()
{
myclass obj;
obj.replace();
return EXIT_SUCCESS;
};
myclass.h
#ifndef MYCLASS_H_
#define MYCLASS_H_
#include <string>
class myclass
{
private:
std::string instruction;
public:
myclass();
std::string replace();
};
#endif
myclass.cpp
#include "myclass.h"
#include <iostream>
myclass::myclass()
{
std::cout<<"I am the constructor"<<std::endl;
}
std::string myclass::replace()
{
std::cout<<"I replace"<<std::endl;
}
std::stringfrommyclass::replaceand you didn't, so that's an issue.