鱼C论坛

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

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

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

    cout << "Enter volume in cubic feet: ";
    cin >> (*ps).volume;        // method 2 for member access
    cout << "Enter price: $";
    cin >> ps->price;
    cout << "Name: " << (*ps).name << endl;                 // method 2
    cout << "Volume: " << ps->volume << " cubic feet\n";    // method 1
    cout << "Price: $" << ps->price << endl;                // method 1
 //   delete ps;
    return 0;
}
gcc 6.4.0
最佳答案
2018-1-10 17:51:56
dt3tc 发表于 2018-1-10 18:48
能不能具体说说改了哪些位置,我看不出来,谢谢

基础不扎实呀
重新学一下C++吧
// newstrct.cpp -- using new with a structure
#include <iostream>
struct inflatabe    //structure template
{
        char name[20];
        float volume;
        double price;
};
//typedef struct inflatable Inflatable;
int main()
{
        using namespace std;
        //struct inflatable * ps;
        struct inflatabe *ps = nullptr;
        //    *ps={"John",3.9,2};
        //    struct inflatable* ps = new inflatable;   // allot memory for structure
        cout << "Enter name of inflatabe item: ";
        cin.get(ps->name, 20);

        cout << "Enter volume in cubic feet: ";
        cin >> (*ps).volume;        // method 2 for member access
        cout << "Enter price: $";
        cin >> ps->price;
        cout << "Name: " << (*ps).name << endl;                 // method 2
        cout << "Volume: " << ps->volume << " cubic feet\n";    // method 1
        cout << "Price: $" << ps->price << endl;                // method 1
                                                                //   delete ps;
        return 0;
}

最佳答案

查看完整内容

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

使用道具 举报

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

基础不扎实呀
重新学一下C++吧
// newstrct.cpp -- using new with a structure
#include <iostream>
struct inflatabe    //structure template
{
        char name[20];
        float volume;
        double price;
};
//typedef struct inflatable Inflatable;
int main()
{
        using namespace std;
        //struct inflatable * ps;
        struct inflatabe *ps = nullptr;
        //    *ps={"John",3.9,2};
        //    struct inflatable* ps = new inflatable;   // allot memory for structure
        cout << "Enter name of inflatabe item: ";
        cin.get(ps->name, 20);

        cout << "Enter volume in cubic feet: ";
        cin >> (*ps).volume;        // method 2 for member access
        cout << "Enter price: $";
        cin >> ps->price;
        cout << "Name: " << (*ps).name << endl;                 // method 2
        cout << "Volume: " << ps->volume << " cubic feet\n";    // method 1
        cout << "Price: $" << ps->price << endl;                // method 1
                                                                //   delete ps;
        return 0;
}
想知道小甲鱼最近在做啥?请访问 -> 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-10-1 07:40

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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