注册 登录
编程论坛 C++教室

帮忙看下,为什么提示我函数没有定义。

书生小白 发布于 2011-09-28 21:12, 786 次点击
#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>
#define TURE 1;
#define ERORR 0;
#define OK 1;
#define FALSE 0;
using namespace std;
class city
{                                           //      用类定义城市坐标
public:
    char name;
    float x;                                                 //         经度
    float y;                                               //      纬度

    class city *next;
    void inset(city *p);
    void set(char n,float a,float b)
    {
        name=n;
        x=a;
        y=b;
    }
};
void city::inset(city *p)
{
    ofstream outfile("date.txt",ios::out);
        if(!outfile)
        {
            cout<<"error"<<endl;
            exit(1);
        }
    while(p->next!=NULL)
    {
        cout<<p->name<<"  "<<p->x<<"  "<<p->y;
        outfile<<p->name<<"  "<<p->x<<"  "<<p->y;
    }
    outfile.close();
}

int main()
{
    char name;
    city c1,c2,c3;
    city *head,*p,*q;
    q=head=new city;
    for(int i=0;i<3;i++)
    {
        p=new city;
        cout<<"name";
        cin>>p->name;
        cout<<"a";
        cin>>p->x;
        cout<<"b";
        cin>>p->y;
        q->next=p;
        q=q->next;
    }
    inset(head);
    return 0;
   
}
3 回复
#2
徐仁强2011-09-28 22:41
inset(head);
需不需要对象的调用;这是类函数void city::inset(*p);   
//例如
 c1.inset(head);
 c2.inset(head);
 c3.inset(head);
//你运行试试
inset是一个类成员函数
head->inset();
insert()这种调用方法,他是去全局空间里面去找insert函数。



[ 本帖最后由 徐仁强 于 2011-9-28 22:53 编辑 ]
#3
lkz1987n2011-09-29 00:08
这代码写的乱。
inset(head);这个函数调用要在前面加上对象(或者对象引用,或者指向对象的指针)
其他的问题自己看着把程序搞明白点。
#4
书生小白2011-09-29 12:04
明白了,多谢两位的帮忙、、、
1