473,387 Members | 1,548 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

cannot implicitly convert type

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
2 6123
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Terminal882003 | last post by:
Hi, Here I have a question about MSCommLib. I need to dynamically add activeX controls that requires run-time license for MSCommLib. The following is the actual code: AxMSCommLib.AxMSComm...
3
by: Anita C | last post by:
I have the foll. code to update the value of an attribute: xmlDocument.Load("abc.xml"); XmlAttribute xmlAttrib = xmlDocument.SelectSingleNode(root/web/theme/@desc); xmlAttrib.Value =...
1
by: Svyatoslav | last post by:
Hi, I have a problem with XmlNodes and my stack. It looks something like this: //declarations XmlNode node, new_node; Stack MyStack = new Stack(); //code MyStack.Push(node);
22
by: Christoph Boget | last post by:
I am getting an error (a few among many) for the following lines of code: retval.BrokerName = (( curRow == System.DBNull.Value ) ? SqlString.Null : (string)curRow ); retval.BrokerGroupId = ((...
6
by: juli | last post by:
I declared: public delegate void PaintEventHandler(object objSender,PaintEventArgs pea); and this.Paint+=new PaintEventHandler(MyPaintHandler); and the: static void MyPaintHandler(object...
2
by: Patrick Olurotimi Ige | last post by:
When i convert:- this code from VB to C# Why do i get error "Cannot implicitly convert type 'object' to 'bool' VB --- If cmdcommand.Parameters("ReturnValue").Value = 1 Then lblStatus.Text =...
9
by: Andy Sutorius | last post by:
Hi, I am receiving the error when compiling the project, "cannot implicitly convert type object to string". The error points to this line of code and underlines the dtrRecipient:...
3
by: Patrick Olurotimi Ige | last post by:
compiling the code below i get the error:- Cannot implicitly convert type 'object'to 'System.Xml.XmlDocument' I'm getting the error on this line:- myXml.Document =...
7
by: groups | last post by:
This is my first foray into writing a generic method and maybe I've bitten off more than I can chew. My intent is to have a generic method that accepts a value name and that value will be...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.