Solved

Templates inside a template

Posted on 1998-02-19
7
219 Views
Last Modified: 2010-04-10
I currently have a fairly basic linklist1 template class set up. I have a list declared as linklist1<Trackdata> trklist. Inside the Trackdata class definition, I also have a  linklist1<Signal>sigList declared.  I have a template function called additem(TYPE d). If I do a trklist.additem(Track), it works fine. But if I do a trklist.siglist.additem(Signal), I get a compile error "Cannot convert parameter from Class Signal to Class Signal" Any idea why this is happening? I have included some source below:
HERE IS MY TEMPLATE DEFINITION:
template<class TYPE>
struct link1{
        TYPE data;
      link1* next;
};

template<class TYPE>
class linklist1{
      private:
            link1<TYPE>* first;
            link1<TYPE>* current;
            link1<TYPE>* previous;
      public:
            linklist1()
            { first = current = previous = NULL;}
            linklist1& operator =(const linklist1& L );
            void additem(TYPE d);            
            void display();
            void Init();
              void GetFirst();
            int Found(TYPE d);
            TYPE GetData(TYPE D);
      };
template<class TYPE>
void linklist1<TYPE>::additem(TYPE d){
link1<TYPE>* newlink = new link1<TYPE>;

      newlink->data = d;
      newlink->next = 0;

        if(!Found(d)){
          if(previous){
                previous->next = newlink;
                newlink->next = current;
          }
          else{
                first = newlink;
                newlink->next = current;
          }
          current = newlink;
       }
}

I DECLARE THIS IN MY DOCUMENT CLASS:
linklist1<Trackdata> trkList;

THE TRACKDATA CLASS IS DECLARED BELOW:
class Trackdata : public CObject
public:
      linklist1<Signal> sig2List;
      linklist1<Message> msg2List;


IN THE DOCUMENT CPP PROGRAM I CALL THE FUNCTION AS SUCH:
Trackdata track1;
Signal sig;
trkList.additem(track1);
track1.sig2List.additem(sig);
      THIS IS WHERE I GET THE COMPILER ERROR!!!!!

0
Comment
Question by:smithc
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 2

Expert Comment

by:mnguyen021997
ID: 1182541
what's the definition of your signal class?
0
 

Author Comment

by:smithc
ID: 1182542
HERE IS THe SIGNAL CLASS:
class Signal : public CObject
{
private:
      int m_x1pos;      // Signal X1 Position
      int m_x2pos;      // Signal X2 Position
      int m_ypos;              // Signal Y Position
      int m_index;      // Unique Signal Identifier
      CString m_name;      // Signal Name
      int m_timeup;      // Signal TimeUp
      int m_dur;            // Signal Duration
      CString m_mod;      // Signal Modulation
      float m_bw;            // Signal Bandwidth
      CString m_type;      // Signal Type
      float m_ss;            // Signal Strength
      float m_freq;      // Signal Frequency      
      int   m_trkid;      // Signal Track ID
public:
      Signal();      
      ~Signal();      
      int  Getdata(Signal &);
      int Setdata();
      int Retdate();
      void Putdata(float, float, int);
      void operator =(const Signal&);
        int operator <(const Signal);
        int operator ==(const Signal);
      friend istream& operator >>(istream &in, Signal &sd);
      friend ostream& operator <<(ostream &out, Signal &sd);
};
0
 
LVL 22

Expert Comment

by:nietod
ID: 1182543
Does your compiler support "nested templates"?  That is, templates declared withing templates?  Some (many?) don't.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:smithc
ID: 1182544
It's VC++ 5.0 (Pro Edition).  I believe it supports nested templates.........
0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 1182545
You are passing arg to additem by value, which means a copy of the Signal value has to be made, but you don't have a copy constructor.

Define a copy constructor for your Signal class.
0
 
LVL 10

Accepted Solution

by:
RONSLOW earned 110 total points
ID: 1182546
Oops - that should have been an answer... define a copy constructor for Signal
0
 

Author Comment

by:smithc
ID: 1182547
Thanks. It worked.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question