简体   繁体   中英

C# no Suitable method found for override

hi this is my base class

public abstract class IEnvelopeFactory {

        public Queue<IEnvelopeFactory> m_Queue;
        //public Queue<IEnvelopeFactory> m_Queue<IEnvelopeFactory>;

        public IEnvelopeFactory(){

        }

        ~IEnvelopeFactory(){

        }

        public virtual void Dispose(){

        }

        /// <summary>
        /// Parsing
        /// </summary>
        /// <param name="input"></param>
        /// <param name="envelope"></param>
        public abstract bool Parse(string input, out Envelope envelope);

        /// <summary>
        /// Formatting
        /// </summary>
        /// <param name="env"></param>
        /// <param name="envStr"></param>
        public abstract bool Format(Envelope env, out string envStr);

    }

and the Child Class is as follows

public class XMLTYPE4Factory : IEnvelopeFactory
    {

        public XMLTYPE4 m_XMLTYPE4;

        public XMLTYPE4Factory()
        {

        }

        ~XMLTYPE4Factory()
        {

        }

        public override void Dispose()
        {

        }

        /// <summary>
        /// Parsing
        /// </summary>
        /// <param name="input"></param>
        public override Envelope Parse(string input)
        {

            return null;
        }

        /// <summary>
        /// Formatting
        /// </summary>
        /// <param name="env"></param>
        public override string Format(Envelope env)
        {

            return "";
        }

    }

I am getting the following error

'XMLTYPE4Factory' does not implement inherited abstract member 
'IEnvelopeFactory.Format(CCN.MSG.ENV.Envelope, out string)' 


'XMLTYPE4Factory' does not implement inherited abstract member 
'IEnvelopeFactory.Parse(string, out CCN.MSG.ENV.Envelope)'

The method signatures don't match:

public abstract bool Parse(string input, out Envelope envelope);
public override Envelope Parse(string input)

Also, you shouldn't really prefix a class name with I if it's not an interface.

Yeah the signature doesn't match what you have defined in the base class. Is format supposed to return a string and have a string as an output parameter as well?

Also the standard naming convention in C# interfaces start with I. You should remove the I prefix from your base class.

public class XMLTYPE4Factory : IEnvelopeFactory {

    public XMLTYPE4 m_XMLTYPE4;

    public XMLTYPE4Factory()
    {

    }

    ~XMLTYPE4Factory()
    {

    }

    public override void Dispose()
    {

    }

    /// <summary>
    /// Parsing
    /// </summary>
    /// <param name="input"></param>
    public override Envelope Parse(string input, out string envStr)
    {
envStr= null;
        return null;
    }

    /// <summary>
    /// Formatting
    /// </summary>
    /// <param name="env"></param>
    public override string Format(Envelope env, out string envStr)
    {
        envStr = null;
        return "";
    }

}

you have not implemented the methods with correct parameters

Envelope env;
string s;

public override Envelope Parse(string input,out Envelope env)
{
    env = new Envelope();
    return env;
}

public override string Format(Envelope env,out string s)
{
    s="somestring";
    return s;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM