String pointers

Pages: 12
Thats the kinda stuff that spelling and grammar checkers do isn't it? The only thing I'm doing here differently is I'm storing the junk for possible later use, storing it in a more logical & appropriate place, because 'cmon how the heck did that -245.1987 get in there? Its obvious that that -245.1987 was intended for something else. What we have here, is possibly 2 different input streams, well that crossed their streams, and thats a very very bad thing, like in the movie ghost busters. The least we can do is store the junk so we can straighten everything out after the Stay Puffed Marshmellow Man quits buggering us.
I think polymorphism and virtual inheritance may make your life much easier in this situation.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
struct Data
{
  virtual Data *Clone() = 0; //Make a copy of...whatever the heck kind of variable this is
  virtual unsigned char Type() = 0; //Get the type in case you need it (for most cases you shouldn't)
  //Add more virtual functions here that would be handled by the derived classes, eg:
  //virtual void Print() = 0;
  //Other class-specific functions should be handled by the derived classes, not by the base (eg Get and Set functions)
  virtual ~Data();
};

class String: Data
{
  string Str;
public:
  String(){}
  String(const String& from) : Str(from.Str) {}
  String(const string& from) : Str(from) {}
  Data *Clone(){ return new String(*this); } //Make a new String
  unsigned char Type(){ return 1; } //This is a string
  string Get(){ return Str; }
  void Set(const string& from){ Str = from; }
};

class Int: Data
{
  int Num;
public:
  Int() : Num(0) {}
  Int(const Int& from) : Num(from.Num) {}
  Int(const int& from) : Num(from) {}
  Data *Clone(){ return new Int(*this); } //Make a new Integer
  unsigned char Type(){ return 2; } //This is an Integer
  string Get(){ return Num; }
  void Set(const int& from){ Num = from; }
};

//And other similar derived classes 
1
2
3
4
vector<Data*> Elements;
Elements.push_back(new String("Hello"));
Elements.push_back(new Int(1337));
//do whatever you want now :) 
Last edited on
 
if (s[j] != "")
Your testing if a specific string in the array is null and then trying to delete each string. Just if(s){delete[] s;}.
Last edited on
I think polymorphism and virtual inheritance may make your life much easier in this situation.


I think polymorphism and virtual in heritance may be a little bit over my head at this point. I don't even understand inheritance yet.

And cmon people ain't no one gonna laugh at my reference to ghost busters?
Topic archived. No new replies allowed.
Pages: 12