Operator Overloading and passing a template into COnstructor

This is a discussion on Operator Overloading and passing a template into COnstructor within the C++ Programming forums, part of the General Programming Boards category; Ok 2 small problems I want to have a template array as a private attribute of a class, how do ...

  1. #1
    Registered User
    Join Date
    Dec 2002
    Posts
    4

    Operator Overloading and passing a template into COnstructor

    Ok 2 small problems

    I want to have a template array as a private attribute of a class, how do i pass this template into the Constructor?

    also i wish to overload an operator, but need to compare attributes of a class which is stored in a template array which itsself is stored in another class, so ive used a pointer to refere to that class.

    im really lost if i can even do this yet alone how to do it...any help would save me thanks.

  2. #2
    Registered User
    Join Date
    Dec 2002
    Posts
    119
    Ask very specific questions and post some (relevant) code to illustrate the problem.

    -Futura
    If you speak or are learning Spanish, check out this Spanish and English Dictionary, it is a handy online resource.
    What happens is not as important as how you react to what happens. -Thaddeus Golas

  3. #3
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,386
    >I want to have a template array as a private attribute of a class,
    >how do i pass this template into the Constructor?

    I do not know exactly what you mean, you mean you have a constructor which has a template as argument?

    For example, assume you have a type derived from the template class vector and you want to create a constructor which accepts a vector, then you could do something like this:

    Code:
    template <class T>
    SortedVector<T>::SortedVector (const vector<T>& v): vector<T> (v)
    {
        // Perhaps sort the vector and do other stuff
    }
    >also i wish to overload an operator, but need to compare
    >attributes of a class which is stored in a template array which
    >itsself is stored in another class, so ive used a pointer to refere
    >to that class.

    Hmmm, a little bit confusing. So you have a template array which consists of elements of class A and the template array is stored in a class B? Then you should make an interface to the elements of class A so that you can reach them. For example a get-function in class A, in your class you can then call the n-th element's get-function.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Passing A Function Into A Constructor
    By fourplay in forum C++ Programming
    Replies: 6
    Last Post: 03-15-2009, 06:06 AM
  2. Passing Functor as template parameter
    By MarkZWEERS in forum C++ Programming
    Replies: 6
    Last Post: 11-09-2008, 08:13 AM
  3. Replies: 6
    Last Post: 12-06-2005, 08:23 AM
  4. Passing Template values on to other classes
    By vinsta18 in forum C++ Programming
    Replies: 5
    Last Post: 10-20-2004, 05:26 PM
  5. question about passing arg in constructor??
    By smd in forum C++ Programming
    Replies: 4
    Last Post: 08-20-2003, 07:31 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21