Re: Help needed with explicit instantiation of template methods

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 6 November 2013 13:46, David Aldrich wrote:
> Hi
>
> I would like some help to solve a C++ template specialisation problem please.  I am working with gcc 4.6.3.

This isn't really a GCC question, it's just about general C++.

> We have written a large class called 'Matrix' to manipulate matrices.  The class is declared in Matrix.h and many of its methods are defined in Matrix.cpp.

Can't you simply define them in the header?

>  The class is used by other modules so, to satisfy the linker, I explicitly instantiate the necessary methods in Matrix.cpp.  My problem concerns one of the those explicit instantiations.
>
> Here is a small part of the declaration in Matrix.h:

It would be a lot more helpful if you show a complete example, reduced
to just the pertinent details, not small parts.  Here's a complete
example:

template<typename T>
class Matrix
{
public:
    Matrix(){}

    Matrix(const Matrix&);

    template<typename U>
        Matrix(const Matrix<U>&) { }
};

template<typename T>
Matrix<T>::Matrix(const Matrix&) {}

template Matrix<int>::Matrix(const Matrix&);

int main()
{
    Matrix<int> m;
    Matrix<int> mm = m;
}


> How can I change the template specialisation to indicate to the compiler that it should use (A) ?

I'm not sure what the right syntax is, different compilers behave differently.

Can you simply instantiate the whole class, instead of the copy constructor?

template class Matrix< std::complex<double> >;




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux