Home creating a simple class and its variables and function keeps returning " segmentation fault (core dumped)", C++
Reply: 0

creating a simple class and its variables and function keeps returning " segmentation fault (core dumped)", C++

user929
1#
user929 Published in July 19, 2018, 11:12 pm

I am new to c++. Ive been trying to make a class, assign private variables to it and make public funcs to modify and reach those variables later. Program keeps returning "Segmentation fault (core dumped) Process returned 139 (0x8B). I know there are similar topics with this error, but not I could not find any suitable solution there. Thank you for your time.

# include <iostream>
# include <string>

using namespace std;

class cars{
    public:
    string yearinsert(int x) {
        year = x;
    }
    string nameinsert(string y) {
        name = y;
    }
    void nameget() {
    cout << name << endl;
    }
    void yearget() {
    cout << year << endl;
    }

private:
    int year;
private:
    string name;

};


int main(){

cars skoda;

skoda.nameinsert("Skoda");
skoda.yearinsert(2012);

skoda.nameget();
skoda.yearget();

return 0;
};
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.328471 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO