|
-
May 3rd, 2011, 06:25 PM
#1
Accessing class functions from parameter of template?
Hey everyone,
I have been having some problems getting my code to compile where I need to have a class studentRecord I defined as one of the types of another template class bst, and then need to use a member function from class studentRecord to return a new type of the template class bst.
My implementation needs to look like this:
int main( )
{
bst<studentRecord, int> *mydb;
mydb = mydb.create_database();
Essentially, i need to create a new bst that with the first type being studentRecord. create_database is a member function of studentRecord, here is the inplementation of that function.
template<class Item, class Key>
bst<studentRecord, int>* studentRecord::create_database()
{
bst<studentRecord, int> blank;
bst<studentRecord, int> *root;
int num_courses = 0;
int count = 0;
string str;
while(true)
{
getline(cin, str);
if (str == ".")break;
else blank.id = atoi(str);
blank.key_value = blank.id;
getline(cin, blank.name);
getline(cin, blank.major);
cin >> num_courses;
for (int j = 0; j < num_courses; ++j)
{
cin >> blank->courses[j].num;
cin >> blank->courses[j].cred;
getline(cin, blank->courses[j].grade);
}
insert_node(blank, blank.key_value, blank.item_value);
for(count; count < 1; count++)
{
root = ␣
}
}
return root;
}
I obviously dont have all the code correct, but I need to get my program to compile before i can test it, and I am having a very hard time figuring out the correct way to call the function from studentRecord to return the correct bst.
The error i am getting right now is,
studentExam.cxx:15: error: request for member `create_database' in `mydb',
which is of non-aggregate type `bst<studentRecord, int>*'
and I cant seem to get anywhere from backwards at this point.
Let me know if posting more code would make the problem clearer.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|