0

I want to have my grid class constructor to take in drivers_location parameters , but it keeps giving me these errors. https://i.stack.imgur.com/jgUUZ.jpg


#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

Jason
  • 36,170
  • 5
  • 26
  • 60
  • Refer to [how to ask](https://stackoverflow.com/help/how-to-ask) where the first step is to *"search and then research"* and you'll find plenty of related SO posts for this. – Jason Oct 09 '22 at 09:50
  • 1
    This is explained in any [beginner c++ book](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list). This `drivers_location(string name, float xx, float yy)` is not what you think it is. – Jason Oct 09 '22 at 09:51

1 Answers1

1

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.

Jason
  • 36,170
  • 5
  • 26
  • 60