我用vc6.0编译一个工程时报错是下面情况:
D:\MyProjects\lc1\main.cpp(22) : error C2065: 'program' : undeclared identifier
Error executing cl.exe.
但是我的函数实现文件中定义声明了program这一函数,请问是什么原因啊?

解决方案 »

  1.   

    错误是未定义,但是不一定是这个错。
    曾经俺用VC2005的时候,就是要打个补丁就避免类似的错误。
    但是VC6.0貌似没有此类BUG,所以还是上下代码
      

  2.   

    #ifndef SEQLIST_H
    #define SEQLIST_H
    template<class Type>class Seqlist
    {
    private:
    Type*elem;
    int length;
    int listsize;
    public:
    Seqlist(int size);
    ~Seqlist(void){delete[]elem;}
    int SeqListLength(void)const{
    return length;
    }
    int SeqListInsert(int i,Type&e);
    Type&SeqGetElem(int i)const{
    return elem[i-1];
    }
    int SeqLocateElem(Type e);
    int ReplaceElem(int i,Type&e);
    };
    #endif

    #include "seqlist.h"
    template <class Type>
    void merge(Seqlist<Type>&la,Seqlist<Type>&lb,Seqlist<Type>&lc)
    {
    Type data;int i;
    int la_length=la.SeqListLength();
    int lb_length=lb.SeqListLength();
    for(i=1;i<la_length;i++)
    {
    data=la.SeqGetElem(i);
    lc.SeqListInsert(i,data);
    }
    int lc_length=lc.SeqListLength();
    for(i=1;i<=lb_length;i++)
    {
    data=lb.SeqGetElem(i);
    if(!lc.SeqLocateElem(data))lc.SeqListInsert(++lc_length,data);
    }}
    template<class Type>void Bubblesort(Seqlist<Type>&lc)
    {
    Type temp;
    int flag=1;
    int n=lc.SeqListLength();
    for(int i=1;i<n&&flag==1;i++)
    {
    flag=0;
    for(int j=1;j<=n-i;j++)
    {
    if(lc.SeqGetElem(j)>lc.SeqgetElem(j+1))
    {
    temp=lc.SeqGetElem(j);
    lc.REplaceElem(j,lc.SeqGetElem(j+1));
    lc.ReplaceElem(j+1,temp);
    flag=1;}
    }}

    template<class Type>
    void program(Seqlist<Type>&la,Seqlist<Type>&lb,Seqlist<Type>&lc)
    {
    merge(la,lb,lc);
    Bubblesort(lc);
    }

    #include <iostream.h>
    #include "seqlist.h"
    #include <stdlib.h>
    void main()
    {
    Seqlist<int>la(10),lb(10),lc(10);
    cout<<"分别输入集合A与集合B的元素个数\n";
    int na,nb,data;
    cin>>na>>nb;
    cout<<"输入集合A的元素\n";
    for(int i=1;i<=na;i++)
    {
    cin>>data;
    la.SeqListInsert(i,data);
    }
    cout<<"输入集合B的元素\n";
    for(int j=1;j<=nb;j++)
    {
    cin>>data;
    lb.SeqListInsert(j,data);
    }
     program(la,lb,lc);
    cout<<"输出计算结果是\n";
    int nc=lc.SeqListLength();
    for(i=1;i<=nc;i++){
    cout<<lc.SeqGetElem(i)<<" ";
    }
    }
      

  3.   

    有人给我说在void main函数前加上template <class Type>
    void merge(Seqlist<Type>&la,Seqlist<Type>&lb,Seqlist<Type>&lc)
    {
    Type data;int i;
    int la_length=la.SeqListLength();
    int lb_length=lb.SeqListLength();
    for(i=1;i<la_length;i++)
    {
    data=la.SeqGetElem(i);
    lc.SeqListInsert(i,data);
    }
    int lc_length=lc.SeqListLength();
    for(i=1;i<=lb_length;i++)
    {
    data=lb.SeqGetElem(i);
    if(!lc.SeqLocateElem(data))lc.SeqListInsert(++lc_length,data);
    }}
    template<class Type>void Bubblesort(Seqlist<Type>&lc)
    {
    Type temp;
    int flag=1;
    int n=lc.SeqListLength();
    for(int i=1;i<n&&flag==1;i++)
    {
    flag=0;
    for(int j=1;j<=n-i;j++)
    {
    if(lc.SeqGetElem(j)>lc.SeqgetElem(j+1))
    {
    temp=lc.SeqGetElem(j);
    lc.REplaceElem(j,lc.SeqGetElem(j+1));
    lc.ReplaceElem(j+1,temp);
    flag=1;}
    }}
    }  
    template<class Type>
    void program(Seqlist<Type>&la,Seqlist<Type>&lb,Seqlist<Type>&lc)
    {
    merge(la,lb,lc);
    Bubblesort(lc);
    }
    这些,但还是不行。。