Linux -Blue forest free software | Return to home page | Site Map | Search WWW | Contact Us |
Your current position : Homepage > Free Software > Technological exchanges >Application Programming


    

Blue Forest http://www.lslnet.com at 10:18 on June 6, 2006


STL list of (difficult), experts advise

Em16 em16 : : : : : : em16 your masters, the younger would like to ask the following questions :
I would like to use the STL list to store a variety of data types, I suppose :
Base-type definitions
Type Type1, Type2, Type3 Base is derived from the sub-class.
Definition :
List<Base>; myList;
Then :
Type1 aa= new Type1 (11);
Type2 bb = new Type2 ( "C");
Data can be inserted into myList how these two were playing?
MyList.push_back (aa);
MyLIst.push_back (bb);
Is not acceptable, then I can not define a list template used to guide operators bars
STL want to use the list to die.
Help!
[color=darkred][/color][color=brown][/color]

STL list of (difficult), experts advise

";>;Type1 Aa= new Type1 (11);
";>;Type2 Bb = new Type2 (" C ");

Look at the object or target is aa and bb

STL list of (difficult), experts advise

I guess you want to write polymorphic functions refund procedures, we write a simple example, we should look at how to use elements of the container.

[code] 1 #include "iostream>;
2 #include "list>;
3 using namespace std;
4
5 class Base
      6 {
Private : 7
8
9 public :
10 virtual void Print () (
11 cout<< "Print function () of class Base," "<endl;
12 }
     13 };
14
15 14.00 Type1:public Base
     16 {
17 private :
18
19 public :
20 void Print () (
21 cout<< "Print function () of 14.00 Type1" "<endl;
22 }
     23 };
24
25 14.00 Type2:public Type1
     26 {
27 private :
28
29 public :
30 void Print () (
31 cout<< "Printf function of class Type2" "<endl;
32 }
     33 };
34
35 int main (int argc, argv char**)
     36 {
37 list<Base *>; ls;
38 Base b1;
39 Type1 t1
40 Type2 t2;
41
42 ls.push_back (&b1);
43 ls.push_back (&t1);
44 ls.push_back (&t2);
45
46 for (itr = ls.begin list<Base *>; : : iterator ();
> Ls.end 47 itr (); Itr++)
48 (*itr) ->;Print ();
49
50 return 0
     51 }
52[/code]

STL list of (difficult), experts advise

Third floor of the master, and did not target? Up not directly targeted?

STL list of (difficult), experts advise

The third floor of experts to help answer this question.
Liberation is not directly generated by the same type of object. You can direct up-or category, but they also have value semantics STL container, not quoted semantics, of course, you can use smart point, a guide packaging easily. not careful there will be problems. directly lead to cutting targets and semantic value.



 Privacy Policy  Copyright © 1999-2000 LSLNET.COM. All rights reserved. Blue Forest website owners. E-mail : Webmaster@lslnet.com