By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,885 Members | 1,252 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,885 IT Pros & Developers. It's quick & easy.

cannot implicitly convert type

P: n/a
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
Nov 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Jeff" <je*******@hotmail.com> wrote in message
news:4j********************************@4ax.com...
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

Nov 17 '05 #2

P: n/a
Thats it!
I have no idea how I missed that !
I will also reduce the number of classes
Thanks
jeff

On Thu, 20 Oct 2005 09:45:11 -0400, "Ignacio Machin \( .NET/ C# MVP
\)" <ignacio.machin AT dot.state.fl.us> wrote:
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,


Nov 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.