Skip to main content
gamedev.net
🔒 Locked

error C2893: Failed to specialize function

Started by Marty666 Apr 30, 2006 at 4:35 PM 7 replies 5k views
Original Post
Marty666
Marty666
hi all. I've got this template function 'eval' in the 'node' class that should be able to handle vector aswell as vector. 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
Marty666
Marty666
Line 49 calls the eval function, where input is a vector:
for (i = 0; i < hiddenNode.size(); i++) hiddenNode.eval(input);


Thanx for the fast reply!
Marty
_ /__ /|| | || MtY | ||_____|/Marty
Marty666
Marty666
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 as a vector 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
Marty666
Marty666
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
Fruny
Fruny
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
Marty666
Marty666
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
Fruny
Fruny
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

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.