c/c++语言开发共享将结构作为指针传递

我正在尝试将结构作为函数参数中的指针传递。 这是我的代码

#include  #include  #include  typedef struct { int yearOfManufacture; char model[50]; bool gasoline; } Car; void PrintCarDetails(Car details); int main (int argc, const char * argv[]) { Car ford; ford.yearOfManufacture = 1997; ford.gasoline = true; strcpy(ford.model, "Focus"); PrintCarDetails(&ford); return 0; } void PrintCarDetails(Car *details) { printf("Car model %s", details->model); } 

我收到一个错误“将汽车传递给不兼容类型汽车的参数。我想念的是什么?

    前瞻性声明应为:

     void PrintCarDetails(Car * details); 

      void PrintCarDetails(Car * details);  

      * 

    在前方声明中缺失。

    函数定义与函数声明不同。 在声明中,您声明aa Car结构应该用作参数,但在定义中您需要指向Car结构的指针。

    您可能错过了PrintCarDetails函数的声明。 应该:

     void PrintCarDetails(Car *details); 

    在这里工作

    这只是一个小错误,您的函数定义和声明不匹配:

    只需修改第12行: void PrintCarDetails(Car *details);

      以上就是c/c++开发分享将结构作为指针传递相关内容,想了解更多C/C++开发(异常处理)及C/C++游戏开发关注计算机技术网(www.ctvol.com)!)。

      本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

      ctvol管理联系方式QQ:251552304

      本文章地址:https://www.ctvol.com/c-cdevelopment/522919.html

      (0)
      上一篇 2020年12月11日
      下一篇 2020年12月11日

      精彩推荐