一个简单位的C++ 类实现
2011-10-20 09:26
218 查看
这个例子的编译环境是VC 6.0,所以每个cpp文件都要带头文件为:
#include "stdafx.h"
这个例子共用到3个文件,一个头文件,一个源文件,一个main文件。
如下所示:
test.h:
test.cpp:
main文件:
本例子中只是简单介绍了C++类的定义以及实现还有在main文件中的使用。关于更进一步的介绍,待续之。
#include "stdafx.h"
这个例子共用到3个文件,一个头文件,一个源文件,一个main文件。
如下所示:
test.h:
#ifndef _FRACTION_H_ #define _FRACTION_H_ #include <string> using namespace std; class Test { public: void set(int xx, int yy); double toDouble() const; double otherDouble(); void toString() const; private: int x; int y; }; #endif
test.cpp:
#include "StdAfx.h" #include "test.h" #include <iostream> using namespace std; void Test::set(int xx,int yy){ x=xx; y=yy; } double Test::toDouble() const{ return x*y; } double Test::otherDouble(){ return 10*x*y; } void Test::toString() const{ cout<<x<<endl; cout<<y<<endl; }
main文件:
// HelloProject.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include<iostream> #include "test.h" using namespace std; const int DASHES = 30; int main(int argc, char* argv[]) { //printf("Hello World!\n"); //cout<<"helloworld"<<endl; //DASHES++; cout<<DASHES<<endl; // Test t; t.set(1,2); t.toString(); return 0; }
本例子中只是简单介绍了C++类的定义以及实现还有在main文件中的使用。关于更进一步的介绍,待续之。
相关文章推荐
- Hypertable一个 C++ 的Bigtable开源实现
- 【c++】实现一个类
- 一个通用的Trie树,标准C++实现
- C++实现一个多线程同步方式的协同工作程序示例
- 纪念逝去的岁月——C++实现一个栈
- 如何用VS2010新建一个类?用来写C++文件的标准格式建立?就是能做到声把声明放在.H里,实现放在.CPP里的
- C++ IO操作API及注意事项(包含一个日志类的实现)
- C++实现的一个循环队列
- 【C++】实现一个简单的单例模式
- 用C++实现void reverse(char* str)函数,即反转一个null结尾的字符串.
- 用C++实现从控制台输入一个方阵并存储显示
- C++ 声明并实现一个日期类(运算符重载)
- 一个C++ delegate的实现
- 一个无聊男人的疯狂《数据结构与算法分析-C++描述》学习笔记 用C++/lua/python/bash的四重实现(4)二分搜索算法
- 从易到难编写C++程序,(8)问题:实现一个矩阵类
- 采用C++的ACE库实现的一个通用的C/S架构通信程序(最终版)
- 一个Windows C++的线程池的实现
- 用c++实现一个n*n矩阵,矩阵沿着45度递增,形成zigzag数组
- 用C++实现一个Log系统
- 一个实用的String实现类(C++)