|
|

楼主 |
发表于 2006-7-26 10:17:05
|
显示全部楼层
自己琢磨一下是这样写的:
Interface.h//
- #define interface struct
- interface IXMLReaderContext
- {
- public:
- virtual void AddAttribute() const = 0;
- virtual void Display() const = 0;
- };
- extern IXMLReaderContext* Initialize();
复制代码
InterfaceImpl.h//
- #include "Interface.h"
- class TVReader : public IXMLReaderContext
- {
- public:
- TVReader(){}
- ~TVReader(){}
- void AddAttribute() const;
- void Display() const;
- };
复制代码
InterfaceImpl.cpp//
- #include <stdlib.h>
- #include <stdio.h>
- #include "InterfaceImpl.h"
- void TVReader::AddAttribute() const
- {
- }
- void TVReader::Display() const
- {
- printf("Inside TVReader...\n");
- }
复制代码
Others.cpp
- #include "InterfaceImpl.h"
- IXMLReaderContext* Initialize()
- {
- TVReader* pTVReader = new TVReader;
- return pTVReader;
- }
复制代码
调试结果:
- [root@root vitual]# g++ -c InterfaceImpl.cpp
- [root@root vitual]# g++ -c Others.cpp
- [root@root vitual]# g++ -c Client.cpp
- [root@root vitual]# ls
- Client.o InterfaceImpl.cpp InterfaceImpl.o Others.cpp
- Client.cpp Interface.h InterfaceImpl.h LIBS Others.o
- [root@root vitual]# mv InterfaceImpl.h InterfaceImpl.cpp Others.cpp LIBS/
- [root@root vitual]# ls
- Client.cpp Client.o Interface.h InterfaceImpl.o libs Others.o
- [root@root vitual]# g++ -o a.out Client.o InterfaceImpl.o Others.o
- [root@root vitual]# ls
- a.out Client.cpp Client.o Interface.h InterfaceImpl.o libs Others.o
- [root@root vitual]# ./a.out
- Inside TVReader...
- [root@root vitual]#
复制代码
这种投机取巧的方法为那些将开源代码商业化提供了一种思路。提供玩玩的一种方法。 |
|