关于创建一个简单窗口的问题(问题在正文中叙述得很清楚)
// 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 个 ==========
*/