Failure in file inclusion
I'm currently studying wxWidgets programming, and everything's going just fine... Except for one part, that is. The project I'm working on is a Celsius to Fahrenheit converter. So far, I have three files: CelsiusFahrenheit.cpp, Utilitarios.h, Utilitarios.cpp, the first of which contains the main program. Here's the code:
CelsiusFahrenheit.cpp
Code:
#define CELSIUS_BUTTON_ID 1
#define FAHRENHEIT_BUTTON_ID 2
#include "wx/wx.h"
#include "Utilitarios.h"
#include <string>
using namespace std;
class CelsiusFahrenheit: public wxApp {
public:
//Variaveis globais
wxTextCtrl* celsius_text;
wxTextCtrl* fahrenheit_text;
//Metodo OnInit, iniciador da aplicacao
bool OnInit() {
//Inicializa a janela
wxSize* tamanho_janela = new wxSize(640,480);
wxString* titulo = new wxString("Conversor Celsius-Fahrenheit-Celsius");
wxFrame* janela = new wxFrame(NULL, -1, *titulo, wxDefaultPosition, *tamanho_janela);
//Inicializa os controlos de texto
int celsius_text_x = 0;
int celsius_text_y = 0;
int fahrenheit_text_x = celsius_text_x;
int fahrenheit_text_y = celsius_text_y + 50;
wxPoint* posicao_celsius_text = new wxPoint(celsius_text_x,celsius_text_y);
wxPoint* posicao_fahrenheit_text = new wxPoint(fahrenheit_text_x,fahrenheit_text_y);
wxSize* tamanho_texto = new wxSize(200, 25);
celsius_text = new wxTextCtrl(janela, -1, "", *posicao_celsius_text, *tamanho_texto);
fahrenheit_text = new wxTextCtrl(janela, -1, "", *posicao_fahrenheit_text, *tamanho_texto);
*celsius_text << "Valor em graus Celsius";
*fahrenheit_text << "Valor em graus Fahrenheit";
//Inicializa os botoes
wxSize* tamanho_botoes = new wxSize(200, 25);
wxPoint* posicao_celsius_button = new wxPoint(celsius_text_x + tamanho_texto->GetWidth(),celsius_text_y);
wxPoint* posicao_fahrenheit_button = new wxPoint(fahrenheit_text_x + tamanho_texto->GetWidth(),fahrenheit_text_y);
wxButton* celsius_button = new wxButton(janela, CELSIUS_BUTTON_ID, "", *posicao_celsius_button, *tamanho_botoes);
wxButton* fahrenheit_button = new wxButton(janela, FAHRENHEIT_BUTTON_ID, "", *posicao_fahrenheit_button, *tamanho_botoes);
celsius_button->SetLabel("Converter Celsius para Fahrenheit");
fahrenheit_button->SetLabel("Converter Fahrenheit para Celsius");
janela->Show(true);
return true;
}
//Tratadores de eventos
void OnCelsiusClick(wxCommandEvent& event) {
string s(celsius_text->GetValue());
int i = stringToInteger(s);
exit(0);
}
void OnFahrenheitClick(wxCommandEvent& event) {
exit(0);
}
//Instrucao necessaria para que esta classe possa tratar eventos
DECLARE_EVENT_TABLE()
};
//Eventos da classe CelsiusFahrenheit
BEGIN_EVENT_TABLE(CelsiusFahrenheit, wxApp)
EVT_BUTTON(CELSIUS_BUTTON_ID, CelsiusFahrenheit::OnCelsiusClick)
EVT_BUTTON(FAHRENHEIT_BUTTON_ID, CelsiusFahrenheit::OnFahrenheitClick)
END_EVENT_TABLE()
//Iniciar a aplicacao
IMPLEMENT_APP(CelsiusFahrenheit)
Utilitarios.h
Code:
#ifndef _UTILITARIOS_H_
#define _UTILITARIOS_H_
class Utilitarios {
public:
int stringToInteger(string& s);
};
#endif
Utilitarios.cpp
Code:
#include "Utilitarios.h"
#include <sstream>
#include <string>
using namespace std;
int Utilitarios::stringToInteger(string& s) {
stringstream temp;
temp << s;
int i = 0;
if (temp >> i) {
return i;
}
else {
throw "Number format exception!";
}
}
And the problem is the following compilation error:
Line 5 - Utilitarios.h - expected `;' before '(' token
What exactly am I doing wrong? Thank you in advance.