Test %temporary; // object creationVariables don't use a % identifier in C++
%temporary.name (temporary); // assigning it a name to the variable
retain = temporary;Even if the above did work you're using the same variable name twice. This would mean you can't access the member variable easily and generally makes it confusing to work with.
Test::create makes and destroys a
Test object with no effect. If you're trying to create a function that e.g. makes a
Test object with a specific variable set then you should use a "constructor":
#include <iostream>
#include <string>
using namespace std;
class Test
{
public:
string name;
//constructors have no return type
Test();
Test(string input);
string getName();
};
//Default for when you put no arguments
Test::Test()
{
name = "unnamed";
}
//Called when you put one argument in
Test::Test(string input)
{
name = input;
}
int main(int argc, char *argv[])
{
//An object you create with no arguments is set to "unnamed"
Test first;
cout << "The first one is " << first.name << endl;
//You can set a variable when creating it
Test second("Foo");
cout << "The second one is named " << second.name << endl;
string input;
cout << endl << endl;
cout << "Enter a name for the next one: ";
cin >> input;
cout << endl;
Test custom(input);
cout << "It's named " << custom.name;
}
The first one is unnamed
The second one is named Foo
Enter a name for the next one: Joe
It's named Joe
For yours specifically, you'd be able to do something like "Test entry(name, value)" from two inputs.
To make things easier you should put everything under 'public' access until you specifically need the variables restricted from outside - otherwise you have to make lots of useless getName/setName/getValue/... methods that don't have any function. (i.e. use it for adding checks "value is more than 0" "name can't be empty" but for these test ones don't)
This just helps with
setting the initial name and value, you can't do Torque's accessing by making strings for names in C++. The closest approximation would be making some kind of data structure (key/value map) to store all your entry objects and looking them up through that.