Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use list<T*> as method's parameter?

Tags:

c++

How to use generics types as params? I have two lists

list<XmlElement*>* childrens;
list<XmlAttribute*>* attributes;

I want transfer this variables as params to method, like this, but it isn't work

void method(list<void*>* l);

P.S. this code should use the minimum possible amount of memory, because microcontrollers has so little RAM.

like image 589
user9039204 Avatar asked Jun 03 '19 12:06

user9039204


1 Answers

May be template would do the trick ?

#include <iostream>
#include <list>

template <class T>
void foo (const std::list<T*>& v)
{
       std::cout << __PRETTY_FUNCTION__ << std::endl;
}
int main()
{
   std::list<int*> v { nullptr, nullptr };

    foo(v);
}
like image 58
Martin Morterol Avatar answered Oct 13 '22 09:10

Martin Morterol