猿问

我是新手,想问一下C++构造类时的错误

#include <iostream>

#include "coordinate.h"

using namespace std;

class Line{

public:

   Line(int x1,int y1,int x2,int y2);

   ~Line();

   void setA(int x,int y);

   void setB(int x,int y);

   void printinfo();

private:

   Coordinate m_coorA;

   Coordinate m_coorB;

};


Line::Line(int x1,int y1,int x2,int y2):m_coorA(x1,y1),coorB(x2,y2)

{

   cout<<"Line"<<endl;

}

Line::~Line(){

    cout<<"~Line"<<endl;

}

void Line::setA(int x,int y){

    m_coorA.setX(x);

    m_coorA.setY(y);

}

void Line::setB(int x,int y){

    m_coorB.setX(x);

    m_coorB.setY(y);

}

void printinfo(){

    cout<<"m_coorA.getX()"<<" "<<"m_coorA.getY()"<<endl;

    cout<<"m_coorB.getX()"<<" "<<"m_coorB.getY()"<<endl;

}

错误提示:class "line" does not have any field named "coorB"


对着天说晚安
浏览 2118回答 2
2回答

scanxu

Line初始化错误Line::Line(int x1,int y1,int x2,int y2):m_coorA(x1,y1),coorB(x2,y2)中的coorB应该改成m_coorB

MadMarical

你好。根据错误提示,你的类大小写错误了。定义时为Line,示例化时为line。
随时随地看视频慕课网APP
我要回答