鱼C论坛

 找回密码
 立即注册
查看: 3912|回复: 3

[已解决]编译报错"对不完全的类型‘struct main()::inflatable’的非法使用"

[复制链接]
发表于 2018-1-10 17:51:55 | 显示全部楼层 |阅读模式
10鱼币
谢谢
  1. // newstrct.cpp -- using new with a structure
  2. #include <iostream>
  3. struct inflatabe    //structure template
  4. {
  5.     char name[20];
  6.     float volume;
  7.     double price;
  8. };
  9. //typedef struct inflatable Inflatable;
  10. int main()
  11. {
  12.     using namespace std;
  13.     struct inflatable * ps;
  14. //    *ps={"John",3.9,2};
  15. //    struct inflatable* ps = new inflatable;   // allot memory for structure
  16.     cout << "Enter name of inflatabe item: ";
  17.     cin.get(ps->name,20);

  18.     cout << "Enter volume in cubic feet: ";
  19.     cin >> (*ps).volume;        // method 2 for member access
  20.     cout << "Enter price: $";
  21.     cin >> ps->price;
  22.     cout << "Name: " << (*ps).name << endl;                 // method 2
  23.     cout << "Volume: " << ps->volume << " cubic feet\n";    // method 1
  24.     cout << "Price: $" << ps->price << endl;                // method 1
  25. //   delete ps;
  26.     return 0;
  27. }
复制代码

gcc 6.4.0
最佳答案
2018-1-10 17:51:56
dt3tc 发表于 2018-1-10 18:48
能不能具体说说改了哪些位置,我看不出来,谢谢

基础不扎实呀
重新学一下C++吧

  1. // newstrct.cpp -- using new with a structure
  2. #include <iostream>
  3. struct inflatabe    //structure template
  4. {
  5.         char name[20];
  6.         float volume;
  7.         double price;
  8. };
  9. //typedef struct inflatable Inflatable;
  10. int main()
  11. {
  12.         using namespace std;
  13.         //struct inflatable * ps;
  14.         struct inflatabe *ps = nullptr;
  15.         //    *ps={"John",3.9,2};
  16.         //    struct inflatable* ps = new inflatable;   // allot memory for structure
  17.         cout << "Enter name of inflatabe item: ";
  18.         cin.get(ps->name, 20);

  19.         cout << "Enter volume in cubic feet: ";
  20.         cin >> (*ps).volume;        // method 2 for member access
  21.         cout << "Enter price: $";
  22.         cin >> ps->price;
  23.         cout << "Name: " << (*ps).name << endl;                 // method 2
  24.         cout << "Volume: " << ps->volume << " cubic feet\n";    // method 1
  25.         cout << "Price: $" << ps->price << endl;                // method 1
  26.                                                                 //   delete ps;
  27.         return 0;
  28. }
复制代码

最佳答案

查看完整内容

基础不扎实呀 重新学一下C++吧
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2018-1-10 17:51:56 | 显示全部楼层    本楼为最佳答案   
dt3tc 发表于 2018-1-10 18:48
能不能具体说说改了哪些位置,我看不出来,谢谢

基础不扎实呀
重新学一下C++吧

  1. // newstrct.cpp -- using new with a structure
  2. #include <iostream>
  3. struct inflatabe    //structure template
  4. {
  5.         char name[20];
  6.         float volume;
  7.         double price;
  8. };
  9. //typedef struct inflatable Inflatable;
  10. int main()
  11. {
  12.         using namespace std;
  13.         //struct inflatable * ps;
  14.         struct inflatabe *ps = nullptr;
  15.         //    *ps={"John",3.9,2};
  16.         //    struct inflatable* ps = new inflatable;   // allot memory for structure
  17.         cout << "Enter name of inflatabe item: ";
  18.         cin.get(ps->name, 20);

  19.         cout << "Enter volume in cubic feet: ";
  20.         cin >> (*ps).volume;        // method 2 for member access
  21.         cout << "Enter price: $";
  22.         cin >> ps->price;
  23.         cout << "Name: " << (*ps).name << endl;                 // method 2
  24.         cout << "Volume: " << ps->volume << " cubic feet\n";    // method 1
  25.         cout << "Price: $" << ps->price << endl;                // method 1
  26.                                                                 //   delete ps;
  27.         return 0;
  28. }
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2018-1-10 18:15:49 | 显示全部楼层
struct inflatabe
struct inflatable *ps;

无标题.png
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2018-1-10 18:48:15 | 显示全部楼层
人造人 发表于 2018-1-10 18:15
struct inflatabe
struct inflatable  *ps;

能不能具体说说改了哪些位置,我看不出来,谢谢
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-3-29 04:09

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表