dt3tc 发表于 2018-1-10 17:51:55

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

谢谢// newstrct.cpp -- using new with a structure
#include <iostream>
struct inflatabe    //structure template
{
    char name;
    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;
        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;
}

人造人 发表于 2018-1-10 18:15:49

struct inflatabe
struct inflatable *ps;

dt3tc 发表于 2018-1-10 18:48:15

人造人 发表于 2018-1-10 18:15
struct inflatabe
struct inflatable*ps;

能不能具体说说改了哪些位置,我看不出来,谢谢
页: [1]
查看完整版本: 编译报错"对不完全的类型‘struct main()::inflatable’的非法使用"