4 Replies - 331 Views - Last Post: 07 October 2012 - 08:45 AM Rate Topic: -----

#1 IngeniousHax  Icon User is offline

  • |>|20-514<|{3|2

Reputation: 78
  • View blog
  • Posts: 1,358
  • Joined: 28-March 09

passing a struct to a templatized parameter

Posted 05 October 2012 - 09:10 PM

Hello all, just a quick question, how can I pass a struct to a templatized parameter?
here is a quick snippet of what I am trying to do:
template<typename T>
circularList::addNodeData(T* data) // want to pass struct here
{
  // use struct here
}


Is This A Good Question/Topic? 0
  • +

Replies To: passing a struct to a templatized parameter

#2 Coding Mash  Icon User is offline

  • New D.I.C Head

Reputation: 4
  • View blog
  • Posts: 26
  • Joined: 29-September 12

Re: passing a struct to a templatized parameter

Posted 06 October 2012 - 04:41 AM

Firstly you are not using correct syntax for defining the function. After using templates, the name of the class changes. Define it this way.
template<typename T>
circularList<T>::addNodeData(T* data) // want to pass struct here
{
  // use struct here
}



Secondly, which sort of struct you want to pass? Is it a struct or pointer to a struct?
Is that of the circularList class?
If yes, pass it like this.
template<typename T>
circularList<T>::addNodeData(circularList<T> &obj) // want to pass struct here
{
  // use struct here
}


Was This Post Helpful? 1
  • +
  • -

#3 vividexstance  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 663
  • View blog
  • Posts: 2,273
  • Joined: 31-December 10

Re: passing a struct to a templatized parameter

Posted 06 October 2012 - 07:23 AM

You do understand what templates are for correct? If you just want to use a certain struct, then you really don't need a template class. If for whatever reason you do need it to be a template class, you should first start off with a regular class and get all the bugs out of it. Then change it to a template class.
Was This Post Helpful? 0
  • +
  • -

#4 IngeniousHax  Icon User is offline

  • |>|20-514<|{3|2

Reputation: 78
  • View blog
  • Posts: 1,358
  • Joined: 28-March 09

Re: passing a struct to a templatized parameter

Posted 06 October 2012 - 02:14 PM

YEah templates are for more generic type programming, I need a template class for later functions, and as for passing the struct, thank you coding mash!
Was This Post Helpful? 0
  • +
  • -

#5 vividexstance  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 663
  • View blog
  • Posts: 2,273
  • Joined: 31-December 10

Re: passing a struct to a templatized parameter

Posted 07 October 2012 - 08:45 AM

One thing you can do is define the template class, and then define a specialization for that struct you need to use. Are you going to be using this class/functions with other types or just this struct?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1