Templates

Hello,

I´m having problems with templates. I will explain my problem(sorry for my bad english).

I have a template like this:

template<TV,TR>

And a class by the name LISTA, so if a want to declare in main I do:

LISTA<int,int> graf;

But the problem is that I dont want int! I want that my TV be locals(city, village) and my TR be roads (freeways, national roads)..

I do I declare that?

LISTA< , > graf;

Thanks
Define the types you want to use and ... use them!
1
2
3
4
5
6
7
8
enum road
{
    freeway,
    national_road,
    //...
};
// do the same for locals
LISTA<local,road> graf;
But city, village, freeways and national roads are classes that inherit atributes from the main classes local and roads...

Can I do that?
Yes, do you have something like this?
1
2
3
4
5
6
7
8
9
10
11
class local
{
    //...
};
class city: public local
{
    //...
};
//same for roads

LISTA<city,freeways> graf;
Exactly like that!
Your template should work fine, do you get any error?
On main:

enum locais{
Cidade, Vila, LocalTuristico
};

enum vias_lig{
EstradaNacional, Autoestrada
};


ListAdjGrafo<locais,vias_lig> graf;

........


case 5:

graf.construir_grafo(graf);
system("pause");
break;

Then on the class ListAdjGrafo:


void ListAdjGrafo<TV,TR>::construir_grafo(ListAdjGrafo<locais,vias_lig> &graf) const{

.....


}


Error:


error C2664: 'ListAdjGrafo<TV,TR>::construir_grafo' : cannot convert parameter 1 from 'ListAdjGrafo<TV,TR>' to 'ListAdjGrafo<TV,TR> &'

On my computer it compiles fine...

Have you overloaded any constructor for your class?
Um... Why are you passing an object of type T to a method of class T? Don't you know about the this pointer?
Topic archived. No new replies allowed.