Thursday, September 19, 2019

c++ - calling template class constructor

Answer



I'm getting hard time figuring out solution for calling constructor of class which uses templates.




--Header file



template 
class Binary_tree
{
string file_name;

list arr_data;
public:
Binary_tree(string fname);

void printArr();
};


--cpp file



template 

Binary_tree::Binary_tree(string fname)
{
File_Name = fname;

total = 0;
root = nullptr;

std::ifstream filestream(fname);
string line;

while (!filestream.eof())
{
filestream >> line;
arr_data.push_back(line);

}
}

template

void Binary_tree::printArr()
{
int size = arr_data.size();

for (int i = 0; i < size; i++)
{

cout << "arr_data [" << i << "] is: " << arr_data[i] << endl;
}
}


--main.cpp



int main(int argc, char** argv)
{
Binary_tree test(file);

test.printArr();

return 0;
}


Right now I'm getting LNK1120 and LNK2019 errors.

No comments:

Post a Comment

hard drive - Leaving bad sectors in unformatted partition?

Laptop was acting really weird, and copy and seek times were really slow, so I decided to scan the hard drive surface. I have a couple hundr...