帮助初学者 [英] Help a beginner

查看:71
本文介绍了帮助初学者的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好专家,

我是C ++的初学者(虽然我知道C)。

我正在尝试编译下面的代码,我得到了

以下错误。

任何人都可以向我解释我的错误吗?

谢谢!

PhilB


myprog2.cpp:在方法`Line :: Line(Point,Point)'':

myprog2.cpp:32:没有用于调用`Point ::的匹配函数Point()''

myprog2.cpp:12:候选者是:Point :: Point(int,int)

myprog2.cpp:9:Point :: Point( const Point&)

myprog2.cpp:32:没有匹配函数来调用`Point :: Point()''

myprog2.cpp:12:候选者是:Point :: Point(int,int)

myprog2.cpp:9:Point :: Point(const Point&)

myprog2.cpp:32:不匹配函数调用`Point :: Point()''

myprog2.cpp:12:候选者是:Point :: Point(int,int)

myprog2.cpp :9:Point :: Point(const Point &)


// ------------------------

class点

{

受保护:

int x;

int y;

public:

Point :: Point(int,int);

};


Point :: Point(int initx, int inity)

{

x = initx;

y = inity;

return;

}


class Line:public Point

{

public:

Point start_point;

Point end_point;


public:

Line :: Line(Point,Point);

};


Line :: Line(Point initp1,Point initp2)

{

start_point = initp1;

end_point = initp2;

返回;

}


main()

{

点p1(10,20);

点p2(20,40);

线l1(p1,p2);

}

// ------------------------

Hello experts,
I am a complete beginner in C++ (although I know C).
I am trying to compile the code below, and I get
the following error.
Can anyone explain to me my mistake?
Thanks!
PhilB

myprog2.cpp: In method `Line::Line (Point, Point)'':
myprog2.cpp:32: no matching function for call to `Point::Point ()''
myprog2.cpp:12: candidates are: Point::Point (int, int)
myprog2.cpp:9: Point::Point (const Point &)
myprog2.cpp:32: no matching function for call to `Point::Point ()''
myprog2.cpp:12: candidates are: Point::Point (int, int)
myprog2.cpp:9: Point::Point (const Point &)
myprog2.cpp:32: no matching function for call to `Point::Point ()''
myprog2.cpp:12: candidates are: Point::Point (int, int)
myprog2.cpp:9: Point::Point (const Point &)

//------------------------
class Point
{
protected:
int x;
int y;
public:
Point::Point(int, int);
};

Point::Point(int initx, int inity)
{
x=initx;
y=inity;
return;
}

class Line:public Point
{
public:
Point start_point;
Point end_point;

public:
Line::Line(Point, Point);
};

Line::Line(Point initp1, Point initp2)
{
start_point=initp1;
end_point=initp2;
return;
}

main()
{
Point p1(10,20);
Point p2(20,40);
Line l1(p1,p2);
}
//------------------------

推荐答案

> // ------------------------
> //------------------------
class Point
{
protected: int x;
int y;
public:
Point :: Point(int,int);
};
class Point
{
protected:
int x;
int y;
public:
Point::Point(int, int);
};




不是Point :: Point(int,int);

但只是Point(int,int);


在Line类中相同。 />



not Point::Point(int, int);
but just Point(int, int);

same in Line class.


" PhilB" < PB ****** @ yahoo.com>在消息中写道

新闻:10 ************************** @ posting.google.c om ...
"PhilB" <pb******@yahoo.com> wrote in message
news:10**************************@posting.google.c om...
你好专家,
我是C ++的初学者(虽然我知道C)。
我正在尝试编译下面的代码,我得到了
以下错误。
任何人都可以向我解释我的错误吗?
谢谢!
PhilB

myprog2.cpp:方法`Line :: Line(Point,Point) '':
myprog2.cpp:32:没有匹配函数来调用`Point :: Point()''
myprog2.cpp:12:候选者是:Point :: Point(int,int)
myprog2.cpp:9:Point :: Point(const Point&)
myprog2.cpp:32:没有匹配函数来调用`Point :: Point()''
myprog2 .cpp:12:候选者是:Point :: Point(int,int)
myprog2.cpp:9:Point :: Point(const Point&)
myprog2.cpp:32:没有匹配函数调用`Point :: Point()''
myprog2.cpp:12:候选者是:Point :: Point(int,int)
myprog2.cpp:9: Point :: Point(const Point&)

// ------------------------
类Point
{
protected:
int x;
int y;
public:
Point :: Point(int,int);
} ; Point :: Point(int initx,int inity)
{
x = initx;
y = inity;
return;
}

类行:public Point
{
公开:
Point start_point;
Point end_point;

公开:
Line :: Line(Point,Point);
};

Line :: Line(Point initp1,Point initp2)
{
start_point = initp1;
end_point = initp2;
返回;
}

main()
{/ p>点p1(10,20);
点p2(20,40);
第l1行(p1,p2);
}
// ---------------- --------
你好,


在课堂上:

class Point
{
protected:
int x;
int y;
public:
Point :: Point(int,int);
^^^^删除Point :: };
Hello experts,
I am a complete beginner in C++ (although I know C).
I am trying to compile the code below, and I get
the following error.
Can anyone explain to me my mistake?
Thanks!
PhilB

myprog2.cpp: In method `Line::Line (Point, Point)'':
myprog2.cpp:32: no matching function for call to `Point::Point ()''
myprog2.cpp:12: candidates are: Point::Point (int, int)
myprog2.cpp:9: Point::Point (const Point &)
myprog2.cpp:32: no matching function for call to `Point::Point ()''
myprog2.cpp:12: candidates are: Point::Point (int, int)
myprog2.cpp:9: Point::Point (const Point &)
myprog2.cpp:32: no matching function for call to `Point::Point ()''
myprog2.cpp:12: candidates are: Point::Point (int, int)
myprog2.cpp:9: Point::Point (const Point &)

//------------------------
class Point
{
protected:
int x;
int y;
public:
Point::Point(int, int);
};

Point::Point(int initx, int inity)
{
x=initx;
y=inity;
return;
}

class Line:public Point
{
public:
Point start_point;
Point end_point;

public:
Line::Line(Point, Point);
};

Line::Line(Point initp1, Point initp2)
{
start_point=initp1;
end_point=initp2;
return;
}

main()
{
Point p1(10,20);
Point p2(20,40);
Line l1(p1,p2);
}
//------------------------ Hello,

In the class as:
class Point
{
protected:
int x;
int y;
public:
Point::Point(int, int); ^^^^remove the "Point::" };




与其他班级相同。


-

Elias


PhilB写道:
PhilB wrote:
你好专家,
我是C ++的初学者(虽然我知道C)。我正在尝试编译下面的代码,我得到以下错误。
任何人都可以向我解释我的错误吗?


从错误信息中不是很明显吗?

谢谢!
PhilB

myprog2.cpp:方法`Line :: Line(Point,Point)'':
myprog2.cpp:32:没有匹配函数来调用`Point :: Point()''


你试着使用默认的构造函数(即`Point :: Point()''),但

你的Point类没有。

myprog2 .cpp:12:候选者是:Point :: Point(int,int)
myprog2.cpp:9:Point :: Point(const Point&)
myprog2.cpp:32:没有匹配函数调用`Point :: Point()''
myprog2.cpp:12:候选者是:Point :: Point(int,int)
myprog2.cpp:9:Point :: Point(const点&)
myprog2.cpp:32:没有匹配函数来调用`Point :: Point()''
myprog2.cpp:12:候选者是:Point :: Point(int,int )
myprog2.cpp:9:Point :: Point(const Point&)

// ------------------- -----
class Point
{
protected:
int x;
int y;
public:
Point :: Point(int,int);
};

Point :: Point(int initx,int inity)
{
x = initx;
y = inity;
返回;
}课程行:公共点
{
公开:
点start_point;
点end_point;

公开:
Line :: Line(Point,Point);
};

Line :: Line(Point initp1,Point initp2)
{
start_point = initp1 ;
end_point = initp2;
返回;
}


由于您没有为Point对象指定初始值设定项,

默认构造函数将用于创建它们,但你没有

一个。试试这个:


Line :: Line(Point initp1,Point initp2)

:start_point(initp1),

end_point (initp2)

{

}


这将使用复制构造函数(由编译器生成

自动创建你的两个Point成员。

main()
{/ p>点p1(10,20);
点p2(20, 40);
第l1行(p1,p2);
}
// ------------------------
Hello experts,
I am a complete beginner in C++ (although I know C).
I am trying to compile the code below, and I get
the following error.
Can anyone explain to me my mistake?
Isn''t it obvious from the error messages?
Thanks!
PhilB

myprog2.cpp: In method `Line::Line (Point, Point)'':
myprog2.cpp:32: no matching function for call to `Point::Point ()''
You try to use the default constructor (i.e. `Point::Point ()''), but
your Point class doesn''t have one.
myprog2.cpp:12: candidates are: Point::Point (int, int)
myprog2.cpp:9: Point::Point (const Point &)
myprog2.cpp:32: no matching function for call to `Point::Point ()''
myprog2.cpp:12: candidates are: Point::Point (int, int)
myprog2.cpp:9: Point::Point (const Point &)
myprog2.cpp:32: no matching function for call to `Point::Point ()''
myprog2.cpp:12: candidates are: Point::Point (int, int)
myprog2.cpp:9: Point::Point (const Point &)

//------------------------
class Point
{
protected:
int x;
int y;
public:
Point::Point(int, int);
};

Point::Point(int initx, int inity)
{
x=initx;
y=inity;
return;
}

class Line:public Point
{
public:
Point start_point;
Point end_point;

public:
Line::Line(Point, Point);
};

Line::Line(Point initp1, Point initp2)
{
start_point=initp1;
end_point=initp2;
return;
}
Since you have not specified an initializer for your Point objects, the
default constructor will be used to create them, but you don''t have
one. Try this instead:

Line::Line(Point initp1, Point initp2)
: start_point(initp1),
end_point(initp2)
{
}

This will use the copy constructor (which is generated by the compiler
automatically) to create your two Point members.

main()
{
Point p1(10,20);
Point p2(20,40);
Line l1(p1,p2);
}
//------------------------






这篇关于帮助初学者的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆