Targeting failure

0

I created a class to display a string on the terminal, but in addition to displaying the string , also displays the following message: "segmentation failure". I debugged with GDB, but I could not resolve the error. Here is the code below:

#ifndef CONNECTION_H
#define CONNECTION_H

#include<string>
#include<iostream>

using std::string;

class Connection {

public:

   Connection();
  ~Connection(); 

  string conexao;
  string getConexao();

};

#endif // CONNECTION_H




#include"teste.h"

Connection::Connection() 
{
  conexao = "sete de setembro";
}


string Connection::getConexao()

{  
  std::cout << conexao << std::endl;
}


Connection::~Connection()
{

}





#include "teste.h"

int main(void)
{

Connection con;
con.getConexao();

return 0;

}
    
asked by anonymous 03.11.2015 / 20:59

1 answer

1

You have created a method that returns a string , but returned nothing. Then it causes an error.

#include<string>
#include<iostream>

using std::string;
using namespace std;

class Connection {
public:
    Connection();
    string conexao;
    string getConexao();
};

Connection::Connection() {
    conexao = "sete de setembro";
}

string Connection::getConexao() {  
    cout << conexao << endl;
    return conexao;
}

int main(void) {
    Connection con;
    con.getConexao();
    return 0;
}

See running on ideone .

    
03.11.2015 / 21:29