Author Topic: Sev needs help with his first object-oriented C++ program.  (Read 1035 times)

Alright, I had to re-read that. Also, for future reference, don't be a richard to someone trying to help you.

From what I gathered, you want the input to become a sub-class of the object Test? As far as I know with C++, this can't be done.

Now, since I am fairly good with object-oriented design, maybe you can explain what you need it for? There could be other possible solutions.
I wanted to make a simple database where I can create a name for an, "Entry" of sorts, and assign it a value. Then I could later enter in said Entry's name and recieve it's value.

So like a key-value pair?

EDIT: Or an associative array, such that in PHP you can access a value in an array by doing Test["q"].

If so, check out the map object:
http://www.cplusplus.com/reference/stl/map/

Funny how it came back to templates?

Essentially you declare the map as Map<string, Test>, where string is the key, and Test is the value.
« Last Edit: April 09, 2011, 09:14:11 PM by Skele »

The variable name "q", "operate", "hello", whatever is in no way stored in the object so can't be used in that way.

Blockland's system (which I assume you're trying to replicate) of something like %scriptObject.setName("Hello"); ("Hello").doThings(); does not happen by default unless you make something like the key/value map as I/Skele mentioned.

I'm not sure about the test program I tried - it works for me but it's partly set up for SDL and this "C++0x" new standard because the features looked cool.

Skele's link there is very useful, usually it's the first result if you look up something like "C++ vector" or "C++ map" so easy to look up what you need. Here's one of their examples of what the key/value map does (to see if it's what you're trying to make)
Code: [Select]
// map::find
#include <iostream>
#include <map>
using namespace std;

int main ()
{
  map<char,int> mymap;
  map<char,int>::iterator it;

  mymap['a']=50;
  mymap['b']=100;
  mymap['c']=150;
  mymap['d']=200;

  it=mymap.find('b');
  mymap.erase (it);
  mymap.erase (mymap.find('d'));

  // print content:
  cout << "elements in mymap:" << endl;
  cout << "a => " << mymap.find('a')->second << endl;
  cout << "c => " << mymap.find('c')->second << endl;

  return 0;
}
Quote from: Console
elements in mymap:
a => 50
c => 150
« Last Edit: April 10, 2011, 04:55:11 AM by Space Guy »