cannot implicitly convert type

J

Jeff

I get the following error:
Cannot implicitly convert type 'Factory.Stack.pArrayStack' to
'Factory.Stack.StackDefs.ImStack'

at compile time.
I thought perhaps there was a mismatch between the interface method
types and the actual implementation types, so I removed all methods
from both the interface and the implementation (pArrayStack ) but
still get the error. Here is the code with just one simple method
still declared and implemented.

Any ideas as to what causes the error?

For the following code samples, all classes are in the
"Factory.Stack" namespace

Here are the basic parts:
public class StackDefs
{
public interface ImStack
{
// void Push(object o);
// object Pop();
bool isEmpty();
}
public interface IStackFactory
{
ImStack CreateStack();
}
}

Then:
public class AbsFactory
{class ArrayStackFactory : StackDefs.IStackFactory
{
public StackDefs.ImStack CreateStack()
{
//Error occurs on the next line on the word "new"
return new pArrayStack();
}
}

And then:
public class pArrayStack
{
// declare some properties
//protected object[] data = new object[10];
protected int pointer= 0;
/**
* check whether this stack is empty
*/
public bool isEmpty()
{
return pointer == 0;
}
//Other methods commented out until error is resolved.
....................

}
I am relatively new to working with interfaces.

Thanks alot
Jeff
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

Why are you declaring so many classes and interfaces inside other classes?

You better use a namespace IF you need to. ( I don't think you need it in
this case though )

Your problem (apart of the above suggestion) is that pArrayStack does not
implement StackDefs.ImStack

if you change the pArrayStack declaration to:

public class pArrayStack : StackDefs.ImStack

you could do it


Cheers,
 
J

Jeff

Thats it!
I have no idea how I missed that !
I will also reduce the number of classes
Thanks
jeff
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top