c++ beginner segmentation fault when using strings -


i'm trying set basic class using std::string function type , variable type, using both gives me segmentation fault. if delete either function or variable, fine. i'm sure i'm making stupid mistake! 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 constructor"<<std::endl; }  std::string myclass::replace() {     std::cout<<"i replace"<<std::endl; } 

you said myclass::replace return std::string every time gets called, didn't returned anything! happened enters realm of undefined behavior, means program misbehave , kill cat.

the solution add return statement @ end of function.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -