【发布时间】:2014-05-13 07:22:10
【问题描述】:
假设我有一个这样的矩形:
Point p1(100,100);
Point p2(300,200);
Graph_lib::Rectangle r(p1,p2);
我还有一个函数,它接受一个矩形并返回一个点,比如说,那个矩形的左上角。例如:
Point N(Graph_lib::Rectangle R1);
我的问题是,首先,如何将 Rectangle r(p1,p2) 发送到 Point N(Graph_lib::Rectangle R1) 函数?然后,如何从该函数返回一个点?
我的 IDE 是 Visual Studio 2012。 这是我运行并得到错误的代码: 错误 8 错误 C2248: 'Graph_lib::Shape::Shape' : 无法访问在类 'Graph_lib::Shape' c:\program files\microsoft visual studio 11.0\vc\include\graph.h 212 中声明的私有成员
#include <Simple_window.h>
Point N(Graph_lib::Rectangle r);
Point s(Graph_lib::Rectangle r);
Point e(Graph_lib::Rectangle r);
Point w(Graph_lib::Rectangle r);
Point ne(Graph_lib::Rectangle r);
Point se(Graph_lib::Rectangle r);
Point nw(Graph_lib::Rectangle r);
Point sw(Graph_lib::Rectangle r);
Point center(Graph_lib::Rectangle r);
//*******************************************************
int main()
{
using namespace Graph_lib;
Simple_window win(Point(100,100), 600,400, "Connection_Points");
Point p1(200,100);
Point p2(400,200);
Graph_lib::Rectangle r (p1,p2);
Mark m(N(r),'x');
win.attach(m);
win.wait_for_button();
}
//*******************************************************************
Point N(Graph_lib::Rectangle r)
{
return r.point(0);
}
//*************************************************
Point s(Graph_lib::Rectangle r);
//*************************************************
Point e(Graph_lib::Rectangle r);
//*************************************************
Point w(Graph_lib::Rectangle r);
//*************************************************
Point ne(Graph_lib::Rectangle r);
//*************************************************
Point se(Graph_lib::Rectangle r);
//*************************************************
Point nw(Graph_lib::Rectangle r);
//*************************************************
Point sw(Graph_lib::Rectangle r);
//*************************************************
Point center(Graph_lib::Rectangle r);
【问题讨论】:
-
请阅读任何 C++ 入门书籍或教程,这将在此处进行介绍。
-
@Mat 奇怪的是,当我对一个展示相同知识/研究水平的问题提出相同的建议时,我被半数的 stackoverflow 社区斥责为粗鲁。名声不足?
-
@o_weisman 也许是最暴躁的 SO 用户现在都睡着了?
-
@Mat: 不,我有 PPP 书,这是一个练习。到目前为止,还没有关于这个问题的任何消息。不幸的是,有人对这个问题投了反对票。很抱歉,我使用 stackoverflow.com 寻求帮助。
-
@abbasi:Stack Overflow 是针对特定编程问题的,它不能替代书籍、培训等。您所问的内容包含在 C++ 的基本学习材料中(所有其他语言都一样)。请花一些时间阅读至少一本书或综合教程。
标签: c++ visual-c++