| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1079 人关注过本帖
标题:这是什么错误?请教!
只看楼主 加入收藏
gaoce227
Rank: 4
来 自:山东
等 级:业余侠客
帖 子:134
专家分:218
注 册:2008-4-5
收藏
 问题点数:0 回复次数:7 
这是什么错误?请教!
插入.cpp
D:\VC++6.0\MSDev98\MyProjects\gg\数据结构1\插入.cpp(15) : error C2440: 'initializing' : cannot convert from 'const int' to 'int *'
        Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
D:\VC++6.0\MSDev98\MyProjects\gg\数据结构1\插入.cpp(15) : error C2440: 'initializing' : cannot convert from 'const int' to 'int *'
        Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
Error executing cl.exe.

插入.obj - 2 error(s), 0 warning(s)
搜索更多相关主题的帖子: convert cannot 
2008-09-27 12:44
fish_rose
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2008-9-22
收藏
得分:0 
不贴代码怎么看啊

看上面意思是你的参数类型不对
2008-09-27 14:48
gaoce227
Rank: 4
来 自:山东
等 级:业余侠客
帖 子:134
专家分:218
注 册:2008-4-5
收藏
得分:0 
回复 2# fish_rose 的帖子
以下是代码: (帮忙改一下,我猜测是main()的问题)
#define LIST_INIT_SIZE 100
#define LISTINCREMENT  10
#include<stdio.h>
#include<malloc.h>
 typedef struct
    {
        char *elem;
        int length;
        int listsize;
    }SqList;
int InitList_Sq(SqList &L);
int ListInsert_Sq(SqList &L,int i,char e);
void main()
{
    
    SqList  aa[2]={'a','b'};
    InitList_Sq(aa[2]);
    ListInsert_Sq(aa[2],1,'Z');
    printf("输出插入后的数组:\n");
        for(int j=0;j<3;j++)
            printf("%c",aa[j]);
        printf("\n");
}
int InitList_Sq(SqList &L){
    L.elem=(char *)malloc(LIST_INIT_SIZE *sizeof(char));
    if(!L.elem)return -2;
    L.length=0;
    L.listsize=LIST_INIT_SIZE;
    return 1;
}
int ListInsert_Sq(SqList &L,int i,char e)
{
    if(i<i || i>L.length+1)return 0;
    if(L.length>=L.listsize){
        char *newbase=(char *)realloc(L.elem,(L.listsize+LISTINCREMENT)*sizeof(char));
        if(!newbase)return -2;
        L.elem=newbase;
        L.listsize+=LISTINCREMENT;
    }
    char *q=&(L.elem[i-1]);
    char *p;
    for(p=&(L.elem[L.length-1]);p>=q;--p)*(p+1)=*p;
    *q=e;
    ++(L.length);
    return 1;
}
2008-09-27 15:16
nuciewth
Rank: 14Rank: 14Rank: 14Rank: 14
来 自:我爱龙龙
等 级:贵宾
威 望:104
帖 子:9786
专家分:208
注 册:2006-5-23
收藏
得分:0 
1.整型赋值给指针类型
    SqList  aa[2]={'a','b'};
这个也是类似的错误

倚天照海花无数,流水高山心自知。
2008-09-27 18:09
fish_rose
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2008-9-22
收藏
得分:0 
楼上正解,建议楼主再看看结构体的知识,这是最基本的结构体赋值问题
2008-09-28 09:04
gaoce227
Rank: 4
来 自:山东
等 级:业余侠客
帖 子:134
专家分:218
注 册:2008-4-5
收藏
得分:0 
回复 5# fish_rose 的帖子
应该怎么改才好呢?
2008-09-28 13:18
zzj19851122
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2008-10-3
收藏
得分:0 
我知道
#include<stdio.h>
#include<malloc.h>
typedef struct
    {
        char *elem;
        int length;
        int listsize;
    }SqList;
int InitList_Sq(SqList &L);
int ListInsert_Sq(SqList &L,int i,char e);
void main()
{
     SqList l;
    char  aa[2]={'a','b'};
    InitList_Sq(l);
    ListInsert_Sq(l,1,'Z');
    printf("输出插入后的数组:\n");
        for(int j=0;j<3;j++)
            printf("%c",aa[j]);
        printf("\n");
}
int InitList_Sq(SqList &L){
    L.elem=(char *)malloc(LIST_INIT_SIZE *sizeof(char));
    if(!L.elem)return -2;
    L.length=0;
    L.listsize=LIST_INIT_SIZE;
    return 1;
}
int ListInsert_Sq(SqList &L,int i,char e)
{
    if(i<i || i>L.length+1)return 0;
    if(L.length>=L.listsize){
        char *newbase=(char *)realloc(L.elem,(L.listsize+LISTINCREMENT)*sizeof(char));
        if(!newbase)return -2;
        L.elem=newbase;
        L.listsize+=LISTINCREMENT;
    }
    char *q=&(L.elem[i-1]);
    char *p;
    for(p=&(L.elem[L.length-1]);p>=q;--p)*(p+1)=*p;
    *q=e;
    ++(L.length);
    return 1;
}
2008-10-03 13:35
gaoce227
Rank: 4
来 自:山东
等 级:业余侠客
帖 子:134
专家分:218
注 册:2008-4-5
收藏
得分:0 
回复 7# zzj19851122 的帖子
运行不出要插入的元素啊
2008-10-04 22:08
快速回复:这是什么错误?请教!
数据加载中...
 
   



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

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