creating base classes from name in file as read

hi, I'm creating a program that takes data
http://football-data.co.uk/mmz4281/1415/E0.csv
ad so far have removed the data i don't want, and want to use inheritance to use a base class and create sub-classes when a team name is read.
is it possible?

can i use something like
name_of_file.getline(home_team, 20,',');
//then create a subclass by:
class "pointer to home team??" : public base_class

thanks
> and want to use inheritance to use a base class and create sub-classes when a team name is read. is it possible?
yes
That's not possible. The input string will be a value in a variable, no way to transfer that to a variable name. You could put the value inside the class as a string member.
@Texano40: Did the OP say he wanted the team name to be the name of the variable?
I think this is what he wants
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
class Base
{
public:
	Base(string name)
	{
		teamName = name;
	}
private:
	string teamName;
};
class Derived : public Base
{
public:
	Derived(string name) : Base(name)
	{}
};

int main()
{
	vector<Derived> teams;
	fstream stream("teams.txt");
	string name;
	
	//read names per line
	while(getline(stream,name))
	{
		Derived team(name);
		teams.push_back(team);
	}
	...
}
	
What shadowCODE posted is your best bet for doing that. You can't create a class object using a string to name that class object (and for good reason; imagine if you had Patriots, Colts, and Steelers as sub classes derived from the base class - the problem would then be you can't use those class objects since your program doesn't know what they are called), but you can store the name of the team within an object as a string member as suggested.
Topic archived. No new replies allowed.