I want to have my grid class constructor to take in drivers_location parameters , but it keeps giving me these errors. https://imgur.com/a/y4MZqso
#include <iostream>
#include <string>
using namespace std;
class drivers_location {
public:
drivers_location() = default;
drivers_location(string name, float xx, float yy){
x = xx;
y = yy;
name = driver_name;
}
private:
float x{};
float y{};
string driver_name;
};
class grid {
public:
grid() = default;
grid(drivers_location(string name, float xx, float yy));
private:
};
int main() {
drivers_location p;
float pointx{ 2.0 };
float pointy{ 3.0 };
grid m[5];
m[0] = { {"abdul" , pointx, pointy }};
}
I want the grid to take in parameters of drivers_location without using inheritance if that's possible
CodePudding user response:
The correct syntax for declaring a constructor takes argument of type driver_location
is as shown below. Note that you don't have to specify the 2 parameters of driver_location
when defining the constructor for grid
that has a parameter of type driver_location
.
class grid {
public:
grid() = default;
//---vvvvvvvvvvvvvvvv---->this is how we specify that this ctor has a parameter of type drivers_location
grid(drivers_location){
//add your code here
}
private:
};
I would also recommend using a good c book.