Jump to content
  • Advertisement
Sign in to follow this  
ndwork

Parse Tree Conversion

This topic is 3580 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

I have used parse trees to implement the '*' operator for my templated container class. The problem is that the parse tree node is not converted back to a container class until the assignment occurs. So the following code causes an error:
int out = myFunc( container1 * container2 );
I am using visual studio 2005. The error code is:
Quote:
error C2784: 'T myFunc(const container<T> &)' : could not deduce template argument for 'const container<T> &' from 'parseTreeNode<T,Left,Op,Right>'
The method that I used to implement the parse tree was described in 'http://www.oonumerics.org/blitz/docs/', for those who are interested. Does anyone have any suggestions?

Share this post


Link to post
Share on other sites
Advertisement
Thank you for your suggestion. I should have mentioned it earlier. I have already implemented a copy constructor in the container class that accepts a parseTreeNode. Did you mean something other than that?

Share this post


Link to post
Share on other sites
I think this is a simplified case of what you are dealing with.


#include <iostream>

template <class N>
struct Y
{
N n;
Y(N n): n(n) {}
};

template <class T>
class X
{
T value;
public:
X(const T& value): value(value) {}
X(const Y<T>& y): value(y.n) {}
friend std::ostream& operator<< (std::ostream& os, const X<T>& x) { return os << x.value; }
};

template <class T>
void foo(const X<T>& x)
{
std::cout << x << '\n';
}

int main()
{
Y<int> y(2);
//foo(y);
foo<int>(y);
}




It indeed won't be able to deduce the required type of X<T> in the foo call, unless the template type is explicitly given. Can't really think of a way to make that happen implicitly.

Share this post


Link to post
Share on other sites
The source code that you've written is exactly my problem.

Had foo accepted a member of type Y, there would not be a compiler error. Foo could deduce its argument from the input parameter.

In this case, though, there is a copy constructor that is being called. Is this the reason why an ambiguity occurs?

Does anyone know a way around this without explicitly defining the type in the function call?


Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!