LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 666|回复: 4

Save object with signle List

[复制链接]
发表于 2006-1-19 14:06:43 | 显示全部楼层 |阅读模式
Hi guys
   I want to orginize a group of Ojbect which is implenmentation of Class with Signle List
How can I to do? for example
   class foo
   {
        public:
         foo();
         ...
         void getData();
         void setData();
         ...
    }
    templae <Class T>
    class SignleList
    {
        public:
          SignleList();
          ...
          T begin();         //How can I to implement the follow method?
          T end();           
          void append();     
          void delete();     
          void sort();
          void find();
          void current();
          ...
     }

    void main()
    {
     foo A;
     SignleList<A> fooList;
     fooList.append(new foo(X1));
     fooList.append(new foo(X2));
     fooList.append(new foo(X3));
     
     foo B;
     for(B=fooList.begin(); ; B=fooList.end())
     {
       cout<<fooList.current.getData()<<endl;
       ...
      }
I have question about that List is only implement the agorithem of itself
 楼主| 发表于 2006-1-19 15:11:18 | 显示全部楼层

  1. class foo
  2. {
  3.     public:
  4.       foo();
  5.       ...
  6.       void getData();
  7.       void setData();
  8.       ...
  9. }
  10. templae <Class T>
  11. class SignleList
  12. {
  13.     public:
  14.       SignleList();
  15.       ...
  16.       T begin(); //How can I to implement the follow method?
  17.       T end();
  18.       void append();
  19.       void delete();
  20.       void sort();
  21.       void find();
  22.       void current();
  23.       ...
  24. }

  25. void main()
  26. {
  27.      foo A;
  28.      SignleList<A> fooList;
  29.      fooList.append(new foo(X1));
  30.      fooList.append(new foo(X2));
  31.      fooList.append(new foo(X3));

  32.      foo B;
  33.      for(B=fooList.begin(); ; B=fooList.end())
  34.      {
  35.         cout<<fooList.current.getData()<<endl;
  36.         ...
  37. }
复制代码
回复 支持 反对

使用道具 举报

发表于 2006-1-19 16:24:28 | 显示全部楼层
signle?single?
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-1-20 09:59:29 | 显示全部楼层
There is vividing saying that Home sometime noding, Needless to say for me. Let's enter into the topic, How can I to implement this method of class, Well, I done like this:

  1. template <class Type>
  2. class List
  3. {   public:
  4.       ...
  5.       void insert();
  6.       void remove();
  7.       ...
  8.     private:
  9.        ListNode<Type>* firstptr;
  10.        LIstNode<Type>* lastptr;
  11. }
  12. template <class Type>
  13. class ListNode       //This class is Interface used between List and Object.do nothing
  14. {                    // in its internal, just to storing Ojbect
  15.     public:
  16.       ...
  17.       
  18.     private:
  19.       Type data;
  20.       ListNode<Type>* nextptr;   //is pointer to point next Object
  21. }

复制代码

Warmly weclome to discuss ,
Best regard
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-1-20 10:05:50 | 显示全部楼层
Anther problem is :

  1. #define USB_MODULE_INIT(module)      \
  2.     extern "C" void USB_##module##_ForceDynamicLink() { } \
  3.     extern "C" Sample *  USB_##module##_Module_Init(Foo *FooTest, bool & Sample)

复制代码

I know "##" is command of pre-handleer for ANSIC C/C++, Well, If there is "USB_MODULE_INIT(module) in running program ,And it is replaced by USB_module_ForceDynamicLink() , My question is what about the next "extern "C" ..." mean?
Best Regard!
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表