DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   C# (http://www.daniweb.com/forums/forum61.html)
-   -   Generic type-union conflict,error? (http://www.daniweb.com/forums/thread158840.html)

ddanbe Nov 21st, 2008 4:35 pm
Generic type-union conflict,error?
 
Busy writing an infix to postfix converter.(I'm a strange guy. I like to do those things from time to time...)
I have a class Expression which is in essence :
 [StructLayout(LayoutKind.Explicit)] //in c/c++ this is a union
        public struct Valoper
        {
            [FieldOffset(0)]
            public int Value;
            [FieldOffset(0)]
            public Oper Operand;
        }
        public Queue<Valoper> RPN = new Queue<Valoper>();

        public Queue<Valoper> InfixToPostfix(string expr)
        {
            //change expr to postfix
            return RPN;
        }
Btw wonder why they left out the union keyword in C#.
I found this "way" to do it in C# on MSDN.
In my Main I have :
Expression E = new Expression();
            Queue<Expression.Valoper> Output = E.InfixToPostfix(InputStr);
The last line gives me the error message

Error 1 Cannot implicitly convert type 'System.Collections.Generic.Queue<ConsoleInfixToPostfix.Expression.Valoper>' to 'System.Collections.Generic.Queue<Valoper>

I'm using VS 2008 Express C# here.
What am I doing wrong? Any help would be nice.

dickersonka Nov 21st, 2008 4:45 pm
Re: Generic type-union conflict,error?
 
hmmm, compiles fine for me

you sure Expression.Valoper is the same class as Valoper?

ddanbe Nov 21st, 2008 5:08 pm
Re: Generic type-union conflict,error?
 
The struct Valoper is defined in the Expression class.
The line with the error I have is called from Main in the Program class. I don't know why it shouldn't work, that's why I posted it here.
Did you really tried it out and it worked at your place?

dickersonka Nov 21st, 2008 5:38 pm
Re: Generic type-union conflict,error?
 
lol yeh man, it worked fine, will you post the whole class structure then?

ddanbe Nov 21st, 2008 5:53 pm
Re: Generic type-union conflict,error?
 
Still wondering 'bout the error message. Difference between pro and express versions? I will mark this as solved.


All times are GMT -4. The time now is 9:53 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC