Witam wlasnie przerobilem odcinek o konstruktorach i destruktorach.
W pliku z nagłówkami ustawiłem konstruktor na domyślne wartości
Event(string="brak",int=1,int=1,int=2018,int=12,int=0);
W mainie stworzylem obiekt
Event w1();
w1.show();
I podczas pokazywania wyskakuje błąd kompilatora:
error: request for member 'show' in 'w1', which is of non-class type 'Event()'
Przeciez ta metoda jest w tej klasie i dodatkowo powiem , że gdy wpisze wszystkie dane to wyswietla się dobrze oraz gdy wpisze np. tylko nazwe to wyswietla się wpisana nazwa + poprawna reszta domyslnie ustawionych zmiennych.
Oto cały kod:
main.cpp
#include <iostream>
#include "eventy.h"
using namespace std;
int main()
{
Event w1(); // tu nastapi wywolanie
w1.show();
return 0;
}
eventy.h
#include <iostream>
using namespace std;
class Event
{
int day, month, year;
int hour, minutes;
string name;
public:
Event(string="brak",int=1,int=1,int=2018,int=12,int=0);
~Event();
void load();
void show();
};
eventy.cpp
#include <iostream>
#include "eventy.h"
using namespace std;
void Event::show()
{
cout<<endl<<name<<" "<<" "<<day<<"."<<month<<"."<<year<<" "<<hour<<":"<<minutes<<endl;
}
Event::Event(string n, int d, int m, int y, int h, int mins) // wez te wartosci i poustawiaj nimi wszystkie wartosci
{
name = n; // uzyj tych zmiennych do inicjowania naszych atrybutow
day = d;
month = m;
year = y;
hour = h;
minutes = mins;
}
Event::~Event()
{
cout << endl << "To ja destruktor sie nazywam.";
cout << " Sprzatam pozostalosci" << endl;
}