473,382 Members | 1,743 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Specialization errors

Hi all,

I have implemented a matrix template to suit my needs and now I've
implemented some methods for computing SVD decomposition of
Matrix<double>.
I have:
template <class T>
class Matrix {
public:
....

Line 45: void svdcmp(Matrix<double> *u, vector<double> *wvec,
Matrix<double> *v);

....
};

Line 365: template <>
Line 366: void Matrix<double>::svdcmp(Matrix<double> *u, vector<double>
*wvec, Matrix<double> *v) {

....

}

I get the following error from gcc-3.3.4:
matrix.hpp:366: error: specialization of void
Matrix<T>::svdcmp(Matrix<double>*, std::vector<double,
std::allocator<double> >*, Matrix<double>*) [with T = double] after
instantiation
matrix.hpp:366: error: prototype for `void
Matrix<T>::svdcmp(Matrix<double>*,
std::vector<double, std::allocator<double> >*, Matrix<double>*)
[with T =
double]' does not match any in class `Matrix<double>'
matrix.hpp:45: error: candidate is: void
Matrix<T>::svdcmp(Matrix<double>*,
std::vector<double, std::allocator<double> >*, Matrix<double>*)
[with T =
double]
matrix.hpp:366: error: `void Matrix<T>::svdcmp(Matrix<double>*,
std::vector<double, std::allocator<double> >*, Matrix<double>*)
[with T =
double]' and `void Matrix<T>::svdcmp(Matrix<double>*,
std::vector<double,
std::allocator<double> >*, Matrix<double>*) [with T = double]'
cannot be
overloaded

This messages can get scary... I can't get where the problem is. Any
ideas?

Cheers,

Paulo Matos

Sep 9 '05 #1
5 1979

"pmatos" <po**@sat.inesc-id.pt> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
Hi all,

I have implemented a matrix template to suit my needs and now I've
implemented some methods for computing SVD decomposition of
Matrix<double>.
I have:
template <class T>
class Matrix {
public:
...

Line 45: void svdcmp(Matrix<double> *u, vector<double> *wvec,
Matrix<double> *v);

...
};

Line 365: template <>
Line 366: void Matrix<double>::svdcmp(Matrix<double> *u, vector<double>
*wvec, Matrix<double> *v) {

I think you mean:

template <typename T>
void Matrix<T>::svdcmp(
Matrix<double>* u, vector<double>*wvec, Matrix<double>* v)
{
// ...
}
OR:

template <>
class Matrix<double>
{
public:
void svdcmp(
Matrix* u, vector<double>* wvec, Matrix* v);
//...
};

void Matrix<double>::svdcmp(
Matrix<double>* u, vector<double>* wvec, Matrix<double>* v)
{
// ...
}

...

}

I get the following error from gcc-3.3.4:
matrix.hpp:366: error: specialization of void
Matrix<T>::svdcmp(Matrix<double>*, std::vector<double,
std::allocator<double> >*, Matrix<double>*) [with T = double] after
instantiation
matrix.hpp:366: error: prototype for `void
Matrix<T>::svdcmp(Matrix<double>*,
std::vector<double, std::allocator<double> >*, Matrix<double>*)
[with T =
double]' does not match any in class `Matrix<double>'
matrix.hpp:45: error: candidate is: void
Matrix<T>::svdcmp(Matrix<double>*,
std::vector<double, std::allocator<double> >*, Matrix<double>*)
[with T =
double]
matrix.hpp:366: error: `void Matrix<T>::svdcmp(Matrix<double>*,
std::vector<double, std::allocator<double> >*, Matrix<double>*)
[with T =
double]' and `void Matrix<T>::svdcmp(Matrix<double>*,
std::vector<double,
std::allocator<double> >*, Matrix<double>*) [with T = double]'
cannot be
overloaded

This messages can get scary... I can't get where the problem is. Any
ideas?

Cheers,

Paulo Matos

Sep 9 '05 #2

benben wrote:
"pmatos" <po**@sat.inesc-id.pt> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
Hi all,

I have implemented a matrix template to suit my needs and now I've
implemented some methods for computing SVD decomposition of
Matrix<double>.
I have:
template <class T>
class Matrix {
public:
...

Line 45: void svdcmp(Matrix<double> *u, vector<double> *wvec,
Matrix<double> *v);

...
};

Line 365: template <>
Line 366: void Matrix<double>::svdcmp(Matrix<double> *u, vector<double>
*wvec, Matrix<double> *v) {

I think you mean:

template <typename T>
void Matrix<T>::svdcmp(
Matrix<double>* u, vector<double>*wvec, Matrix<double>* v)
{
// ...
}


This will define svdcmp for all T of Matrix. Which should not be the
case. I can have a Matrix of anything but svdcmp should only work for
double.
OR:

template <>
class Matrix<double>
{
public:
void svdcmp(
Matrix* u, vector<double>* wvec, Matrix* v);
//...
};

void Matrix<double>::svdcmp(
Matrix<double>* u, vector<double>* wvec, Matrix<double>* v)
{
// ...
}

Probably this is the solution but won't this conflict with Matrix<T>
methods?


...

}

I get the following error from gcc-3.3.4:
matrix.hpp:366: error: specialization of void
Matrix<T>::svdcmp(Matrix<double>*, std::vector<double,
std::allocator<double> >*, Matrix<double>*) [with T = double] after
instantiation
matrix.hpp:366: error: prototype for `void
Matrix<T>::svdcmp(Matrix<double>*,
std::vector<double, std::allocator<double> >*, Matrix<double>*)
[with T =
double]' does not match any in class `Matrix<double>'
matrix.hpp:45: error: candidate is: void
Matrix<T>::svdcmp(Matrix<double>*,
std::vector<double, std::allocator<double> >*, Matrix<double>*)
[with T =
double]
matrix.hpp:366: error: `void Matrix<T>::svdcmp(Matrix<double>*,
std::vector<double, std::allocator<double> >*, Matrix<double>*)
[with T =
double]' and `void Matrix<T>::svdcmp(Matrix<double>*,
std::vector<double,
std::allocator<double> >*, Matrix<double>*) [with T = double]'
cannot be
overloaded

This messages can get scary... I can't get where the problem is. Any
ideas?

Cheers,

Paulo Matos


Sep 9 '05 #3

benben wrote:

template <>
class Matrix<double>
{
public:
void svdcmp(
Matrix* u, vector<double>* wvec, Matrix* v);
//...
};

void Matrix<double>::svdcmp(
Matrix<double>* u, vector<double>* wvec, Matrix<double>* v)
{
// ...
}


There's an issue with having:

template <class T>
class Matrix {
public:
void foo();
...
};

template<class T>
void Matrix<T>::foo() {
....
}

template <>
class Matrix<double> {
public:
void onlyfordouble();
};

void Matrix<double>::onlyfordouble() {
// CAN'T ACCESS FOO
}

onlyfordouble() cannot access foo but it should be accessible since foo
is defined for all T, so should be defined for double too!

Sep 9 '05 #4

pmatos wrote:
benben wrote:

template <>
class Matrix<double>
{
public:
void svdcmp(
Matrix* u, vector<double>* wvec, Matrix* v);
//...
};

void Matrix<double>::svdcmp(
Matrix<double>* u, vector<double>* wvec, Matrix<double>* v)
{
// ...
}


There's an issue with having:

template <class T>
class Matrix {
public:
void foo();
...
};

template<class T>
void Matrix<T>::foo() {
...
}

template <>
class Matrix<double> {
public:
void onlyfordouble();
};

void Matrix<double>::onlyfordouble() {
// CAN'T ACCESS FOO
}

onlyfordouble() cannot access foo but it should be accessible since foo
is defined for all T, so should be defined for double too!


Since you have specialized the Matrix template for the type double, the
Matrix<double> class will have only those members and methods declared
in the specialization. Matrix<double> does not "inherit" the routines
declared in the Matrix class template. If Matrix<double> should have a
foo method, it has to declare one.

It's also unclear whether a Matrix<double> specialization is even
needed. Matrix<T> already declares a svd routine that accepts only
Matrix<double> parameters. Does the Matrix object itself also need to
be a Matrix<double>? Even if it does, the svd routine in Matrix<T>
could be changed to accept Matrix<T> parameters. The instantiation of a
Matrix<double> would have then an svd method that would accept
Matrix<double> parameters without requiring specialization.

Greg

Sep 10 '05 #5

"pmatos" <po**@sat.inesc-id.pt> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...

benben wrote:

template <>
class Matrix<double>
{
public:
void svdcmp(
Matrix* u, vector<double>* wvec, Matrix* v);
//...
};

void Matrix<double>::svdcmp(
Matrix<double>* u, vector<double>* wvec, Matrix<double>* v)
{
// ...
}


There's an issue with having:

template <class T>
class Matrix {
public:
void foo();
...
};

template<class T>
void Matrix<T>::foo() {
...
}

template <>
class Matrix<double> {
public:
void onlyfordouble();
};

void Matrix<double>::onlyfordouble() {
// CAN'T ACCESS FOO
}

onlyfordouble() cannot access foo but it should be accessible since foo
is defined for all T, so should be defined for double too!


pmatos,

Even though Matrix<double> and Matrix<T> come from a single template, they
are ultimately two distinct types. One way to share common elements between
different types is to factor out the common elements to a base class
(template). E.g.

template <typename T>
class Matrix_base
{
public:
void foo(void);
};

template <typename T>
class Matrix: private Matrix_base<T>
{
public:
using Matrix_base::foo; // make foo available
// ...
};

template <>
class Matrix<double>: private Matrix_base<double>
{
public:
using Matrix_base::foo;
void onlyfordouble();
};

Regards,
Ben
Sep 10 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Dave | last post by:
Hello all, I am trying to create a full specialization of a member function template of a class template. I get the following errors: Line 29: 'foo<T1>::bar' : illegal use of explicit...
3
by: Ruben Campos | last post by:
Greetings. Please, take a look to the next code, where I have a problem with specialization of class member functions. // ########## CPrinter.h ########## #ifndef PRINTER_H #define PRINTER_H ...
1
by: ranges22 | last post by:
****************************************************************** I am compiling a librarry which has a .h file containing th following:...
6
by: wkaras | last post by:
I tried a couple of compilers, and both gave errors compiling this: template <bool fin, typename T> T foo(T val); template <typename T> T foo<true, T>(T val) { return(val); } But both gave...
7
by: Kufa | last post by:
Hi, I am probably asking for something which was discussed several times, but all my researches were unsucessfull. If you look at this code (simplified part of my project): ---------------...
6
by: merdem | last post by:
Hi all, I just started to mess around with templates. First I declared a class Image as follows(this is a small version of the real thing which is pretty big): template<int depth, int space,...
2
by: VB | last post by:
Hi, I was attempting to implement partial specialization using VC 2005. However i cannot get my code to compile :( .. Can you please help me? template <typename TYPE1> class myClass<TYPE1,...
5
by: dascandy | last post by:
The following program produces no warnings, no errors, but doesn't do what I expect it to. I expect it to produce a warning or error. What does the standard say about this and/or what should it...
13
by: mike b | last post by:
Hello everyone, thanks in advance for your help. I'm new to C++ templates and have run into some issues using member function templates. I have a shared library containing templates that I'm...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.