24小时热门版块排行榜    

查看: 3295  |  回复: 1

zhangguoli13

银虫 (小有名气)

[求助] c++头文件中已经定义的函数,实现时提示不是类的成员函数 已有1人参与

这是头文件
# include <Grids.hpp>//StringGrid
# include <Sysdefs.h>//AnsiString
# include <fstream>//ifstream ofstream

/*地质库*/
#ifndef GEOLOGY
#define GEOLOGY

struct geoldata;
class geology;

/*地质库数据*/
struct geoldata
{
        AnsiString name;//地址类型名称
        float E;//土体弹性模量
        float mu;//土体泊松比
        float gamma;//土体容重
        float c;//土体粘聚力
        float K0;//土体静土压力系数
        float phi;//土体摩擦角
        float f[5];//土体摩擦系数
};

/*地质库类*/
class geology
{
        protected:
                int count;//地质库地址类型个数,0为空状态
                bool ischeck;//数据是否被检查过
                geoldata *data;//地址类型构架指针,动态内存分配,顺序线性表,简单数组

        public:
                geology();//无参构造
                geology(geology const &geol);//拷贝构造,主要处理指针成员
                ~geology();//析构,注意释放空间

                geology operator=(const geology &geol);//重载=,作用类似拷贝构造函数

                bool add(AnsiString iname,float iE,float imu,float igamma,float ic,float iK_0,float iphi,float if1,float if2,float if3,float if4,float if5);//添加
                bool set(AnsiString iname,float iE,float imu,float igamma,float ic,float iK_0,float iphi,float if1,float if2,float if3,float if4,float if5,bool change);//更改
                bool dele(int num);//删除指定标号,如果已经为空,注意释放空间
                bool empty();//清空,注意释放空间
                bool iswrong(int *num,int *var,AnsiString *reason);//检查错误,有错返回true,并将标号、变量、原因写入相应指针指定数组

                int getcount();//返回count
                int getnum(AnsiString findname);//查找地质库名称返回标号
                geoldata get(int num);//返回相应地质库数据

                bool gridout(TStringGrid *StringGrid);//将数据打印在StringGrid上
                bool gridout(TStringGrid *StringGrid,AnsiString findname,int row);//将相应数据打印StringGrid在指定行上

                bool excelread(Variant Sheet);//从excel导入,empty决定是否追加
                bool excelwrite(Variant Sheet);//导出到excel
                bool binread(std::ifstream &infile);//从二进制文件导入,empty决定是否追加
                bool binwrite(std::ofstream &outfile);//保存为二进制文件
};

#endif
下面是类的实现
# include <Grids.hpp>//StringGrid
# include <Sysdefs.h>//AnsiString
# include <fstream>//ifstream ofstream

# include "Comobj.hpp"
# include "geology.h"



/************************************************************************/
geology::geology():count(0),ischeck(false),data(NULL){}
/************************************************************************/
geology::geology(geology const &geol)
{
        if(geol.count==0)
                data=NULL;
        else
        {
                data=new geoldata[geol.count];
                for(int i=0;i<geol.count;i++)
                {
                        data.name=geol.data.name;
                        data.E=geol.data.E;
                        data.mu=geol.data.mu;
                        data.gamma=geol.data.gamma;
                        data.c=geol.data.c;
                        data.K0=geol.data.K0;
                        data.phi=geol.data.phi;
                        data.f[0]=geol.data.f[0];
                        data.f[1]=geol.data.f[1];
                        data.f[2]=geol.data.f[2];
                        data.f[3]=geol.data.f[3];
                        data.f[4]=geol.data.f[4];
                }
        }
        count=geol.count;
        ischeck=geol.ischeck;

}
/************************************************************************/
geology::~geology()
{
        if(data!=NULL)
        delete []data;
}
/************************************************************************/
geology geology::operator=(const geology &geol)
{
        if(this==&geol)
                return *this;

        if(count!=0)
                delete []data;
        count=geol.count;
        ischeck=geol.ischeck;

        if(count==0)
                return *this;

        data=new geoldata[geol.count];
        for(int i=0;i<geol.count;i++)
        {
                data.name=geol.data.name;
                data.E=geol.data.E;
                data.mu=geol.data.mu;
                data.gamma=geol.data.gamma;
                data.c=geol.data.c;
                data.K0=geol.data.K0;
                data.phi=geol.data.phi;
                data.f[0]=geol.data.f[0];
                data.f[1]=geol.data.f[1];
                data.f[2]=geol.data.f[2];
                data.f[3]=geol.data.f[3];
                data.f[4]=geol.data.f[4];
        }
        return *this;
}
/************************************************************************/
bool geology::add(AnsiString iname,float iE,float imu,float igamma,float ic,float iK_0,float iphi,float if1,float if2,float if3,float if4,float if5)
{

        geoldata *temp;
        temp=new geoldata[count+2];

               if(count==0)
        {
                temp[count].name=iname;
                temp[count].E=iE;
                temp[count].mu=imu;
                temp[count].gamma=igamma;
                temp[count].c=ic;
                temp[count].K0=iK_0;
                temp[count].phi=iphi;
                temp[count].f[0]=if1;
                temp[count].f[1]=if2;
                temp[count].f[2]=if3;
                temp[count].f[3]=if4;
                temp[count].f[4]=if5;
                data=temp;
                count++;
                return true;
        }

        for(int i=0;i<count;i++)
        {
                if(data.name==iname)
                return false;
        }


        for(int i=0;i<count;i++)
        {
                       temp.name=data.name;
                       temp.E=data.E;
                       temp.mu=data.mu;
                       temp.gamma=data.gamma;
                       temp.c=data.c;
                       temp.K0=data.K0;
                       temp.phi=data.phi;
                       temp.f[0]=data.f[0];
                       temp.f[1]=data.f[1];
                       temp.f[2]=data.f[2];
                       temp.f[3]=data.f[3];
                       temp.f[4]=data.f[4];
               }

        temp[count].name=iname;
        temp[count].E=iE;
        temp[count].mu=imu;
        temp[count].gamma=igamma;
        temp[count].c=ic;
        temp[count].K0=iK_0;
        temp[count].phi=iphi;
        temp[count].f[0]=if1;
               temp[count].f[1]=if2;
               temp[count].f[2]=if3;
               temp[count].f[3]=if4;
               temp[count].f[4]=if5;
        delete data;
        data=temp;
        count++;
        ischeck=false;
        return true;
}
/************************************************************************/
bool geology::set(AnsiString iname,float iE,float imu,float igamma,float ic,float iK_0,float iphi,float if1,float if2,float if3,float if4,float if5,bool change)
{
        for(int i=0;i<count;i++)
        {
                if(data.name.AnsiCompare(iname)==0)
                {
                        data.name=iname;
                        data.E=iE;
                        data.mu=imu;
                        data.gamma=igamma;
                        data.c=ic;
                        data.K0=iK_0;
                        data.phi=iphi;
                        data.f[0]=if1;
                               data.f[1]=if2;
                               data.f[2]=if3;
                               data.f[3]=if4;
                               data.f[4]=if5;
                        ischeck=false;
                        return true;
                }
        }
         return false;
}
/************************************************************************/
bool geology::dele(int num)
{
        if(num>=0&&num<=count-1)
        {
                for(int i=num;i<count-1;i++)
                {
                        data.name=data[i+1].name;
                               data.E=data[i+1].E;
                        data.mu=data[i+1].mu;
                             data.gamma=data[i+1].gamma;
                            data.c=data[i+1].c;
                           data.K0=data[i+1].K0;
                        data.phi=data[i+1].phi;
                         data.f[0]=data[i+1].f[0];
                        data.f[1]=data[i+1].f[1];
                               data.f[2]=data[i+1].f[2];
                              data.f[3]=data[i+1].f[3];
                             data.f[4]=data[i+1].f[4];
                    }
                delete &data[count-1];
                //&data[count-1]=NULL;        //这个指针付null时为什么有错误呢?
                   count--;
                  return true;
        }
        
        return false;
}
/************************************************************************/
bool geology::empty()
{
        if(count==0)
        return false;
        
        delete []data;
        data=NULL;             //我试过了,data不会自动为空。
        count=0;
        ischeck=true;
        return true;
}
/************************************************************************/
bool geology::iswrong(int *num,int *var,AnsiString *reason)
{
        /*1.name为空;
        2.弹性模量,土体容重,土体黏聚力,摩擦系数,土体静土压力系数大于0
        3.泊松比0~0.5;
        4。土体摩擦角0~180.

        5.12个参数任意一个为空时

        */

        return true;
}
/************************************************************************/
int geology::getcount()
{
        return count;
}
/************************************************************************/
int geology::getnum(AnsiString findname)
{
        for(int i=0;i<count;i++)
        {
                if(data.name.AnsiCompare(findname)==0)
                return i;
        }
        return -1;
}
/************************************************************************/
geoldata geology::get(int num)
{
        geoldata temp;
        temp.name="";

        if(num>=0&&num<count)
        return this->data[num];
        return temp;                     
}
/************************************************************************/
bool geology::gridout(TStringGrid *StringGrid)
{
        int fixr,fixc,sr,sc;
        fixr=StringGrid->FixedRows;
        //fixc=StringGrid->FixedCols;
        sr=StringGrid->RowCount;
        sc=StringGrid->ColCount;

        //if(sr<(count+fixr)|sc<12)    //Stringgrid行数或列数太少时返回
              //  return false;
        if(sc<12)                      //stringgrid只有列数太少时返回。
                return false;
        for(int i=0;i<count;i++)
        {
                if(i<sr)              //判断是否超出了stringgrid的行数,如果超出则不再打印
                {
                StringGrid->Cells[0][i+fixr]=data.name;
                StringGrid->Cells[1][i+fixr]=data.E;
                StringGrid->Cells[2][i+fixr]=data.mu;
                StringGrid->Cells[3][i+fixr]=data.gamma;
                StringGrid->Cells[4][i+fixr]=data.c;
                StringGrid->Cells[5][i+fixr]=data.K0;
                StringGrid->Cells[6][i+fixr]=data.phi;
                StringGrid->Cells[7][i+fixr]=data.f[0];
                StringGrid->Cells[8][i+fixr]=data.f[1];
                StringGrid->Cells[9][i+fixr]=data.f[2];
                StringGrid->Cells[10][i+fixr]=data.f[3];
                StringGrid->Cells[11][i+fixr]=data.f[4];
                }
        }
        return true;
}
/************************************************************************/
bool geology::gridout(TStringGrid *StringGrid,AnsiString findname,int row)
{
        int fixr,fixc,sr,sc,r;
        fixr=StringGrid->FixedRows;
        //fixc=StringGrid->FixedCols;
        sr=StringGrid->RowCount;
        //sc=StringGrid->ColCount;
        r=row+fixr;
        //if(sr<(count+fixr)|sc<12)
         //       return false;

        for(int i=0;i<count;i++)
        {
                if(data.name.AnsiCompare(findname)==0&&row>=1&&row<=sr)      //row的取值范围为1~sr.
                {
                        StringGrid->Cells[0][r-1]=data.name;
                        StringGrid->Cells[1][r-1]=data.E;
                        StringGrid->Cells[2][r-1]=data.mu;
                        StringGrid->Cells[3][r-1]=data.gamma;
                        StringGrid->Cells[4][r-1]=data.c;
                        StringGrid->Cells[5][r-1]=data.K0;
                        StringGrid->Cells[6][r-1]=data.phi;
                        StringGrid->Cells[7][r-1]=data.f[0];
                        StringGrid->Cells[8][r-1]=data.f[1];
                        StringGrid->Cells[9][r-1]=data.f[2];
                        StringGrid->Cells[10][r-1]=data.f[3];
                        StringGrid->Cells[11][r-1]=data.f[4];
                        return true;
                }
        }
        return false;
}
/************************************************************************/
bool geology::excelread(Variant Sheet)
{
        int HANG,LIE,i(2),j(1);

        if(count!=0)
        {
                delete []data;
                count=0;
        }

        while(!(Sheet.OlePropertyGet("Cells", i, 1).OlePropertyGet("Value")).IsEmpty())
        {
                HANG=i-1;
                i++;
        }
        while(!(Sheet.OlePropertyGet("Cells", 1, j).OlePropertyGet("Value")).IsEmpty())
        {
                LIE=j;
                j++;
        }
       if(!(LIE==12|LIE==0))
        {                                                                       
                //ShowMessage("导入文件不符合规定,请重新选择");
                return false;
        }

        for(i=2;i<=HANG+1;i++)
        {
                AnsiString iname=Sheet.OlePropertyGet("Cells", i, 1).OlePropertyGet("Value");
                float iE=StrToFloat(Sheet.OlePropertyGet("Cells", i, 2).OlePropertyGet("Value"));
                float imu=StrToFloat(Sheet.OlePropertyGet("Cells", i, 3).OlePropertyGet("Value"));
                float igamma=StrToFloat(Sheet.OlePropertyGet("Cells", i, 4).OlePropertyGet("Value"));
                float ic=StrToFloat(Sheet.OlePropertyGet("Cells", i, 5).OlePropertyGet("Value"));
                float iK_0=StrToFloat(Sheet.OlePropertyGet("Cells", i, 6).OlePropertyGet("Value"));
                float iphi=StrToFloat(Sheet.OlePropertyGet("Cells", i, 7).OlePropertyGet("Value"));
                float if1=StrToFloat(Sheet.OlePropertyGet("Cells", i, 8).OlePropertyGet("Value"));
                float if2=StrToFloat(Sheet.OlePropertyGet("Cells", i, 9).OlePropertyGet("Value"));
                float if3=StrToFloat(Sheet.OlePropertyGet("Cells", i, 10).OlePropertyGet("Value"));
                float if4=StrToFloat(Sheet.OlePropertyGet("Cells", i, 11).OlePropertyGet("Value"));
                float if5=StrToFloat(Sheet.OlePropertyGet("Cells", i, 12).OlePropertyGet("Value"));
                add(iname,iE,imu,igamma,ic,iK_0,iphi,if1,if2,if3,if4,if5);
        }

        return true;
}
/************************************************************************/
bool geology::excelwrite(Variant Sheet)
{
        Sheet.OlePropertyGet("Cells", 1, 1).OlePropertySet("Value", "地址类型名称");
        Sheet.OlePropertyGet("Cells", 1, 2).OlePropertySet("Value", "土体弹性模量");
        Sheet.OlePropertyGet("Cells", 1, 3).OlePropertySet("Value", "土体泊松比");
        Sheet.OlePropertyGet("Cells", 1, 4).OlePropertySet("Value", "土体容重");
        Sheet.OlePropertyGet("Cells", 1, 5).OlePropertySet("Value", "土体粘聚力");
        Sheet.OlePropertyGet("Cells", 1, 6).OlePropertySet("Value", "土体静土压力系数");
        Sheet.OlePropertyGet("Cells", 1, 7).OlePropertySet("Value", "土体摩擦角");
        Sheet.OlePropertyGet("Cells", 1, 8).OlePropertySet("Value", "土体摩擦系数1");
        Sheet.OlePropertyGet("Cells", 1, 9).OlePropertySet("Value", "土体摩擦系数2");
        Sheet.OlePropertyGet("Cells", 1, 10).OlePropertySet("Value", "土体摩擦系数3");
        Sheet.OlePropertyGet("Cells", 1, 11).OlePropertySet("Value", "土体摩擦系数4");
        Sheet.OlePropertyGet("Cells", 1, 12).OlePropertySet("Value", "土体摩擦系数5");

        for(int i=2;i<count+2;i++)
        {
                Sheet.OlePropertyGet("Cells", i, 1).OlePropertySet("Value", WideString(data[i-2].name));
                Sheet.OlePropertyGet("Cells", i, 2).OlePropertySet("Value", data[i-2].E);
                Sheet.OlePropertyGet("Cells", i, 3).OlePropertySet("Value", data[i-2].mu);
                Sheet.OlePropertyGet("Cells", i, 4).OlePropertySet("Value", data[i-2].gamma);
                Sheet.OlePropertyGet("Cells", i, 5).OlePropertySet("Value", data[i-2].c);
                Sheet.OlePropertyGet("Cells", i, 6).OlePropertySet("Value", data[i-2].K0);
                Sheet.OlePropertyGet("Cells", i, 7).OlePropertySet("Value", data[i-2].phi);
                Sheet.OlePropertyGet("Cells", i, 8).OlePropertySet("Value", data[i-2].f[0]);
                Sheet.OlePropertyGet("Cells", i, 9).OlePropertySet("Value", data[i-2].f[1]);
                Sheet.OlePropertyGet("Cells", i, 10).OlePropertySet("Value", data[i-2].f[2]);
                Sheet.OlePropertyGet("Cells", i, 11).OlePropertySet("Value", data[i-2].f[3]);
                Sheet.OlePropertyGet("Cells", i, 12).OlePropertySet("Value", data[i-2].f[4]);
        }
        return true;
}
/************************************************************************/
bool geology::binread(std::ifstream &infile)
{
        if(!infile)
        {
                //ShowMessage("打开出错!");
                return false;
        }
        for(int i=0;i<count;i++)
        {
                infile.read((char *)&data,sizeof(data));
        }
        infile.read((char *)&count,sizeof(count));
        infile.read((char *)&ischeck,sizeof(ischeck));
        infile.close();
        return true;
}  
/************************************************************************/
bool geology::binwrite(std::ofstream &outfile)
{
        for(int i=0;i<count;i++)
        {
                outfile.write((char *)&data,sizeof(data));
        }
        outfile.write((char *)&count,sizeof(count));
        outfile.write((char *)&ischeck,sizeof(ischeck));
        outfile.close();
        return true;
}

主要是set函数,运行时提示不是成员函数
回复此楼

» 猜你喜欢

» 本主题相关价值贴推荐,对您同样有帮助:

已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

masharp

金虫 (小有名气)

【答案】应助回帖

感谢参与,应助指数 +1
我的经验是调用格式不对吧。你具体的调用形式是什么样子呢?是不是少写了参数什么的或者没有使用限定符、
2楼2014-02-26 09:59:02
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
相关版块跳转 我要订阅楼主 zhangguoli13 的主题更新
信息提示
请填处理意见