Cześć,
Potrzebowałbym pomocy - chciałbym za pomocą konstruktora zmienić wartość zmiennej statycznej. Natomiast utknąłem na błędzie
punkt1.h|14|error: 'Punkt1::Punkt1()' cannot be overloaded with 'Punkt1::Punkt1()'|
Korzystałem z takiego wzorca: https://pl.wikipedia.org/wiki/Zmienna_statyczna
Mój kod poniżej:
//main.cpp
#include <iostream>
#include "punkt1.h"
#include "punkt2.h"
using namespace std;
int main()
{
cout<<"Witaj!"<<endl;
Punkt1 punkt1;
Punkt2 punkt2;
return 0;
}
//////////////////////////////////////////////
//punkt1.cpp
#include <iostream>
#include "punkt1.h"
using namespace std;
int Punkt1::statyczna1 = 0;
Punkt1::Punkt1()
{
std::cout<<"Domyslne wspolrzedne punktu to:"<<std::endl;
wyswietl();
p1=5;
p2=4;
std::cout<<"Wspolrzedne ustalone to: "<<std::endl;
wyswietl();
cout <<"Podaj swoja pierwsza wspolrzedna:" <<endl;
cin >> p1;
cout <<"Podaj swoja druga wspolrzedna:" <<endl;
cin >> p2;
cout << "Twoja pierwsza wspolrzedna pierwszego konstruktora to:" << endl;
cout << p1<<endl;
cout << "Twoja druga wspolrzedna pierwszego konstruktora to:" << endl;
cout << p2<<endl;
cout << "zmienna statyczna z konstruktora to:" << endl;
cout << Punkt1::statyczna1 << endl;
void Punkt1::wyswietl()
{
cout<<p1<<endl;
cout<<p2<<endl;
}
////////////////////////////////////////////////
//punkt1.h
#ifndef PUNKT1_H
#define PUNKT1_H
class Punkt1
{
private:
int p1,p2;
void wyswietl();
public:
Punkt1();
static int statyczna1;
Punkt1() {statyczna1++;}
};
#endif*/
/////////////////////////////////////////////////////
//punkt2.cpp
#include <iostream>
#include "punkt2.h"
using namespace std;
Punkt2::Punkt2():p1(2),p2(4)
{
cout<<"Wspolrzedne ustalone w drugim konstruktorze to: "<<endl;
cout<<p1<<endl;
cout<<p2<<endl;
cout <<"Podaj twoja pierwsza wspolrzedna:" <<endl;
cin >> p1;
cout <<"Podaj twoja druga wspolrzedna:" <<endl;
cin >> p2;
cout << "Twoja pierwsza wspolrzedna drugiego konstruktora to:" << endl;
cout << p1<<endl;
cout << "Twoja druga wspolrzedna drugiego konstruktora to:" << endl;
cout << p2<<endl;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//punkt2.h
#ifndef PUNKT2_H
#define PUNKT2_H
//
class Punkt2
{
private:
int p1,p2;
public:
Punkt2();
};
#endif