标题:帮忙看看是哪里的问题,我一直找不出来。。
只看楼主
任重道远
Rank: 1
等 级:新手上路
帖 子:57
专家分:7
注 册:2015-9-12
结帖率:66.67%
 问题点数:0 回复次数:1 
帮忙看看是哪里的问题,我一直找不出来。。
程序代码:
#include <iostream>
#include <stdlib.h>

using namespace std;

struct Teacher
{
    int age;
};

int getTeacher(Teacher **p)
{
    if(p == NULL)
    {
        return -1;
    }

    Teacher *temp;
    temp = (Teacher *)malloc(sizeof(Teacher));
    if(temp = NULL)
    {
        return -1;
    }

    temp->age = 23;
    *p = temp;

    return 0;
}

int main()
{
    Teacher *pt = NULL;
    getTeacher(&pt);

    cout << "pt->age=" << pt->age << endl;
    cout << "Hello world!" << endl;
    system("pause");
    return 0;
}
2015-11-09 19:40
任重道远
Rank: 1
等 级:新手上路
帖 子:57
专家分:7
注 册:2015-9-12
得分:0 
回复 楼主 任重道远
。。找出来了
其中的if(temp == NULL)写成了if(temp = NULL)......
2015-11-09 19:44



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-459037-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.385638 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved