Template classes and friend functions


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Template classes and friend functions

  1. #1
    Dohojar Guest

    Template classes and friend functions


    I created a class for a growning array. The array can get bigger or
    smaller depending on what I want to do with it. Now I had written all
    the code for this class and designed it around an int array type and the
    code worked fine. So then I make this array class into a template class and
    I am getting linker errors. Now I know this is caused by the friend function
    I have inside this class(well I think I know). my question is this, it there
    a differnt way to declare friend functions in a template class than normal...
    argh.

  2. #2
    Danny Kalev Guest

    Re: Template classes and friend functions

    I don't think the errors are caused by the friend declaration. It's hard
    to guess what exactly is wrong without seeing the code and the error
    messages, but you should remember that unlike ordinary classes and
    functions, templates' definitions (i.e., implementation) should appear
    in the same translation unit as the declarations. In other words, if
    your class a separate .h file and a .cpp implementation file, you
    should move all the .cpp contents into the .h file.

    Danny

    Dohojar wrote:
    >
    > I created a class for a growning array. The array can get bigger or
    > smaller depending on what I want to do with it. Now I had written all
    > the code for this class and designed it around an int array type and the
    > code worked fine. So then I make this array class into a template class and
    > I am getting linker errors. Now I know this is caused by the friend function
    > I have inside this class(well I think I know). my question is this, it there
    > a differnt way to declare friend functions in a template class than normal...
    > argh.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center