Sign in to follow this  

error C2893: Failed to specialize function

This topic is 4244 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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[i] = 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[i] * inputWeight[i];
    }
    lastInput = value;
    value = sigmoid(value);
}



Can anyone help out? Thanx, Marty [Edited by - Marty666 on April 30, 2006 4:55:15 PM]

Share this post


Link to post
Share on other sites
Line 49 calls the eval function, where input is a vector<double>:

for (i = 0; i < hiddenNode.size(); i++) hiddenNode[i].eval(input);



Thanx for the fast reply!
Marty

Share this post


Link to post
Share on other sites
Hi,

I read the link xEricx send. It seems to me the error is in the function where i use the value input[i]. 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[i]) * inputWeight[i];
}
lastInput = value;
value = sigmoid(value);
}


Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

This topic is 4244 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this