error C2893: Failed to specialize function

Started by
7 comments, last by Fruny 17 years, 11 months ago
hi all. I've got this template function 'eval' in the 'node' class that should be able to handle vector<double> aswell as vector<node>. Only I get this error:

...\neuralnet.cpp(49) : error C2893: Failed to specialize function
template 'void __thiscall node::eval(const class std::vector<T,
class std::allocator<T> > &)'
With the following template arguments:'double'
Here's the relevant source of node:

// nnet.h

class node
{
public:
	node::node(unsigned int numInputs) : lastInput(0)
    {
    	inputWeight.resize(numInputs);
        for (unsigned int i = 0; i < numInputs; i++) inputWeight = rand() / static_cast<double>(RAND_MAX);
    }
    template<typename T> void eval(const std::vector<T> &input);
    operator double() const {return value;}
	double getWeight(unsigned int weightNum) const;
	void setWeight(unsigned int weightNum, double newWeight);
	double getLastInput() const;
	void setValue(double newValue);
private:
	std::vector<double> inputWeight;
	double value;
	double lastInput;
};


// nnet.cpp

template<typename T>
void node::eval(const std::vector<T> &input)
{
    assert(input.size() == inputWeight.size());
    value = 0;
    for(unsigned int i = 0; i < input.size(); i++)
    {
        value += input * inputWeight;
    }
    lastInput = value;
    value = sigmoid(value);
}



Can anyone help out? Thanx, Marty [Edited by - Marty666 on April 30, 2006 4:55:15 PM]
_____ /____ /|| | || MtY | ||_____|/Marty
Advertisement
I've never seen this error. What's on line 49 of neuralnet.cpp?

You might want to check this out.

Also, you might wanna switch value from double to T?

Cheers
Line 49 calls the eval function, where input is a vector<double>:
for (i = 0; i < hiddenNode.size(); i++) hiddenNode.eval(input);


Thanx for the fast reply!
Marty
_____ /____ /|| | || MtY | ||_____|/Marty
Hi,

I read the link xEricx send. It seems to me the error is in the function where i use the value input. Both a vector<double> as a vector<node> would be able to return a double, so I don't get why I still get the error. I tried to static_cast the value (see below), but it didn't help.

Anyone know what's wrong?

Marty

template<typename T>void node::eval(const std::vector<T> &input){    assert(input.size() == inputWeight.size());    value = 0;    for(unsigned int i = 0; i < input.size(); i++)    {        value += static_cast<double>(input) * inputWeight;    }    lastInput = value;    value = sigmoid(value);}
_____ /____ /|| | || MtY | ||_____|/Marty
Hey

Very strange:

I copy pasted the implementation of the 'eval' function to the definition and the problem seems to be solved...
I'm using MSVC6.0, might this be a bug?

I'll also try it with the GNU GCC compiler... I'll let you know.

Marty
_____ /____ /|| | || MtY | ||_____|/Marty
Quote:Original post by Marty666
I'm using MSVC6.0, might this be a bug?


MSVC6's template support is notoriously bad. You are long overdue for a compiler upgrade.

"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
You can download for free the VC++ 2005 express edition
Thanx all!

I know the compiler is old, but didn't know it was buggy. I used the compiler that comes with code::blocks and it works fine now :D.

I just love the extensive documentation with MSVC and code::blocks doesn't seem to have any documentation. Also it doesn't automatically track variables.

I'll try the 2005 version.

Thanx for all the help!
Marty
_____ /____ /|| | || MtY | ||_____|/Marty
Quote:Original post by Marty666
I just love the extensive documentation with MSVC and code::blocks doesn't seem to have any documentation.


The GCC documentation is here.

"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan

This topic is closed to new replies.

Advertisement