关于创建一个简单窗口的问题(问题在正文中叙述得很清楚)

mathcc 2011-09-01 10:53:05
// This is example code from Chapter 12.3 "A first example" of
// "Programming -- Principles and Practice Using C++" by Bjarne Stroustrup
//代码如下(Visual Studio 2008中文版):
//在一个窗口里画一个三角形
#include"D:\My Documents\Visual Studio 2008\Projects\Simple_window.h" // get access to our window library
#include"D:\My Documents\Visual Studio 2008\Projects\Graph.h" //get access to our graphics library facilities
int main()
{
using namespace Graph_lib; // our graphics facilities are in Graph_lib
Point tl(100,100); // to become top left corner of window
Simple_window win(tl,600,400,"Canvas"); // make a simple window
Polygon poly; // make a shape (a polygon)
poly.add(Point(300,200)); // add a point
poly.add(Point(350,100)); // add another point
poly.add(Point(400,200)); // add a third point
poly.set_color(Color::red); // adjust properties of poly
win.attach (poly); // connect poly to the window
win.wait_for_button(); // give control to the display engine
}
/*直接或间接要用到的头文件有:Graph.h GUI.h Point.h
Simple_window.h std_lib_facilities.h Window.h
头文件在http://www.stroustrup.com/Programming中获取,因为上述头文件可能与其它库中的头文件内容不同,所以建议在该网站下载头文件,然后在头文件中修改相应的路径“#include"...."”。
代码运行后显示的问题如下:

1>------ 已启动生成: 项目: chapter12_3, 配置: Debug Win32 ------
1>正在编译...
1>_1.cpp
1>d:\my documents\visual studio 2008\projects\graph.h(45) : warning C4305: “初始化”: 从“Graph_lib::Color::Transparency”到“char”截断
1>d:\my documents\visual studio 2008\projects\graph.h(45) : warning C4309: “初始化”: 截断常量值
1>d:\my documents\visual studio 2008\projects\graph.h(47) : warning C4305: “初始化”: 从“Graph_lib::Color::Transparency”到“char”截断
1>d:\my documents\visual studio 2008\projects\graph.h(47) : warning C4309: “初始化”: 截断常量值
1>d:\my documents\visual studio 2008\projects\graph.h(141) : error C2955: “Vector”: 使用类 模板 需要 模板 参数列表
1> d:\my documents\visual studio 2008\projects\std_lib_facilities.h(76) : 参见“Vector”的声明
1> d:\my documents\visual studio 2008\projects\gui.h(99): 参见对正在编译的类 模板 实例化“Graph_lib::Vector_ref<T>”的引用
1> with
1> [
1> T=Graph_lib::Button
1> ]
1>d:\my documents\visual studio 2008\projects\gui.h(107) : warning C4018: “<”: 有符号/无符号不匹配
1>d:\my documents\visual studio 2008\projects\gui.h(112) : warning C4018: “<”: 有符号/无符号不匹配
1>d:\my documents\visual studio 2008\projects\gui.h(117) : warning C4018: “<”: 有符号/无符号不匹配
1>生成日志保存在“file://d:\My Documents\Visual Studio 2008\Projects\chapter12_3\chapter12_3\Debug\BuildLog.htm”
1>chapter12_3 - 1 个错误,7 个警告
========== 生成: 成功 0 个,失败 1 个,最新 0 个,跳过 0 个 ==========
*/


...全文
143 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
mathcc 2011-09-01
  • 打赏
  • 举报
回复
谢谢您的回复。
我也知道问题出在这里,我是C++新手,就是不知道怎么改。
我再看看吧,也请大家帮帮忙。
luciferisnotsatan 2011-09-01
  • 打赏
  • 举报
回复
错误提示不是手的很清楚了?
1>d:\my documents\visual studio 2008\projects\graph.h(141) : error C2955: “Vector”: 使用类 模板 需要 模板 参数列表

自己去看看graph.h文件的第141行有什么问题
mathcc 2011-09-01
  • 打赏
  • 举报
回复
我可以问问这个大牛么......
jackyjkchen 2011-09-01
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 mathcc 的回复:]

恕不没有一一回复了。

我把代码和运行后的问题都写在正文里面的,请各位再看看我对问题的描述(写得很清楚了)。

我就是建的win32工程哈,用的是fltk1.1.10。

根据我的推测,可能是头文件的问题(想法很疯狂,也可能很幼稚)。

插一句,我用的是《C++程序设计原理与实践》中文版。作者:Bjarne Stroustrup。王刚等翻译

一个人自学,没有人带,痛苦得很
……
[/Quote]
原来如此,C++之父的新书啊

去年还是今年初来着被忽悠买了一本,很薄还不便宜……里头那个图形库加上我看书那一次和您这一次,总共第二次听说……

楼主,不是说大牛提到的东西就一定值得学习的……
赵4老师 2011-09-01
  • 打赏
  • 举报
回复
SAMPLES\MFC\scribble\step1~7\
谁学逆向工程 2011-09-01
  • 打赏
  • 举报
回复
main怎么可能出现窗口呢?
mathcc 2011-09-01
  • 打赏
  • 举报
回复

#include "D:\My Documents\Visual Studio 2008\Projects\Simple_window.h" #include"D:\My Documents\Visual Studio 2008\Projects\Graph.h"
int main()
{
using namespace Graph_lib; // our graphics facilities are in Graph_lib
Point tl(100,100); // to become top left corner of window
Simple_window win(tl,600,400,"Canvas"); // make a simple window
Polygon poly; // make a shape (a polygon)
poly.set_color(Color::red); // adjust properties of poly
poly.add(Point(300,200)); // add a point
poly.add(Point(350,100)); // add another point
poly.add(Point(400,200)); // add a third point
win.attach (poly); // connect poly to the window
win.wait_for_button(); // give control to the display engine
}
mathcc 2011-09-01
  • 打赏
  • 举报
回复
我刚刚在csdn混哈,还不晓得怎样插入代码,就直接把代码像文字一样直接复制粘贴了。现在想修改也来不及了,因为不能修改回复过的帖子
mathcc 2011-09-01
  • 打赏
  • 举报
回复
恕不没有一一回复了。

我把代码和运行后的问题都写在正文里面的,请各位再看看我对问题的描述(写得很清楚了)。

我就是建的win32工程哈,用的是fltk1.1.10。

根据我的推测,可能是头文件的问题(想法很疯狂,也可能很幼稚)。

插一句,我用的是《C++程序设计原理与实践》中文版。作者:Bjarne Stroustrup。王刚等翻译

一个人自学,没有人带,痛苦得很
ctreewang 2011-09-01
  • 打赏
  • 举报
回复
< <<<< 有问题,,,,,帮顶把代码贴出来了
luciferisnotsatan 2011-09-01
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 mathcc 的回复:]

谢谢您的回复。
我也知道问题出在这里,我是C++新手,就是不知道怎么改。
我再看看吧,也请大家帮帮忙。
[/Quote]
把报错的那块代码贴出来。
jackyjkchen 2011-09-01
  • 打赏
  • 举报
回复
你用的什么库?

如果是想建一个窗口,直接新建Win32工程就是一个窗口,别整那些非主流的
至善者善之敌 2011-09-01
  • 打赏
  • 举报
回复
帮顶,楼主解决没?

15,446

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 非技术区
社区管理员
  • 非技术区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧