C++ structs as arguments explained 🚚

Поділитися
Вставка
  • Опубліковано 15 гру 2024

КОМЕНТАРІ • 10

  • @BroCodez
    @BroCodez  2 роки тому +11

    #include
    struct Car{
    std::string model;
    int year;
    std::string color;
    };
    void printCar(Car &car);
    void paintCar(Car &car, std::string color);
    int main () {
    Car car1;
    Car car2;
    car1.model = "Mustang";
    car1.year = 2023;
    car1.color = "red";
    car2.model = "Corvette";
    car2.year = 2024;
    car2.color = "blue";
    paintCar(car1, "silver");
    paintCar(car2, "gold");
    printCar(car1);
    printCar(car2);
    return 0;
    }
    void printCar(Car &car){
    std::cout

  • @Dazza_Doo
    @Dazza_Doo 2 роки тому +1

    Struts are value types when passing to functions/methods and need the ( Type &local_variable ) to pass the Pointer/address
    In C# this would be egregious but this is C++ baby, I need all the help I can get

  • @FrederikWollert
    @FrederikWollert 7 місяців тому

    Good Video but you could've showed more the code from above where you refered from. Other than that good Video.

  • @PCgamers69420
    @PCgamers69420 2 місяці тому

    struct Weapon
    {
    std::string modle;
    double fireRate;
    bool isAuto;
    }
    void Shoot(Weapon)
    {
    Weapon weapon1;
    weapon1;
    weapon1;weapon1;

  • @wjoud1226
    @wjoud1226 7 місяців тому +7

    my brain rotted

  • @danaildoganov
    @danaildoganov 8 місяців тому +1

    #include
    struct player{
    std::string name;
    int age;
    std::string team;
    };
    void printPlayer(player player);
    void changeTeam(player &player, std::string team);
    int main(){
    player player1;
    player1.name = "Messi";
    player1.age = 38;
    player1.team = "Barcelona";
    player player2;
    player2.name = "Ronaldo";
    player2.age = 40;
    player2.team = "Real Madrid";
    changeTeam(player1, "Inter Miami");
    changeTeam(player2, "Al Nassr");
    printPlayer(player1);
    printPlayer(player2);
    return 0;
    }
    void printPlayer(player player){
    std::cout