Witam! Mam np klase, w ktorej tworzę konstruktor majacy dwa argumenty. Potem w main tworze obiekt typu mojej klasy np:
Pojazd tab[10], to jak wywolac tutaj konstruktor dla pierwszego elementu tablicy?
Witam! Mam np klase, w ktorej tworzę konstruktor majacy dwa argumenty. Potem w main tworze obiekt typu mojej klasy np:
Pojazd tab[10], to jak wywolac tutaj konstruktor dla pierwszego elementu tablicy?
nie da sie. Tablice musisz zrobić dynamiczna i tworzyc za pomoca operatora new.
zrezygnuj z tablic korzystaj z vectora.
#include <iostream>
using namespace std;
class Vehicle {
public:
Vehicle() { cout << "ctor-default\n"; }
Vehicle(int) { cout << "ctor-args\n"; }
Vehicle& operator=(const Vehicle&) = delete;
};
int main() {
Vehicle arr[10] = {Vehicle(10)};
return 0;
}
Ew.
#include <iostream>
using namespace std;
class Vehicle {
public:
Vehicle() { cout << "ctor-default\n"; }
Vehicle(int) { cout << "ctor-args\n"; }
Vehicle(const Vehicle&) = delete;
Vehicle& operator=(const Vehicle&) = delete;
};
int main() {
Vehicle arr[10] = {{10}};
return 0;
}