| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 781 人关注过本帖
标题:帮忙看下,为什么提示我函数没有定义。
只看楼主 加入收藏
书生小白
Rank: 2
等 级:论坛游民
帖 子:39
专家分:16
注 册:2011-6-14
结帖率:42.86%
收藏
 问题点数:0 回复次数:3 
帮忙看下,为什么提示我函数没有定义。
#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;
   
}
搜索更多相关主题的帖子: include public class using 
2011-09-28 21:12
徐仁强
Rank: 2
等 级:禁止访问
帖 子:26
专家分:42
注 册:2011-9-14
收藏
得分:0 
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 编辑 ]
2011-09-28 22:41
lkz1987n
Rank: 2
等 级:论坛游民
帖 子:10
专家分:18
注 册:2011-9-8
收藏
得分:0 
这代码写的乱。
inset(head);这个函数调用要在前面加上对象(或者对象引用,或者指向对象的指针)
其他的问题自己看着把程序搞明白点。
2011-09-29 00:08
书生小白
Rank: 2
等 级:论坛游民
帖 子:39
专家分:16
注 册:2011-6-14
收藏
得分:0 
明白了,多谢两位的帮忙、、、
2011-09-29 12:04
快速回复:帮忙看下,为什么提示我函数没有定义。
数据加载中...
 
   



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

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