【问题标题】:VC++ / CLI abstract method implementation problem for c#c#的VC++/CLI抽象方法实现问题
【发布时间】:2010-12-15 07:56:43
【问题描述】:

我正在开发一个 pdf 类库项目。我为所有输出进程创建了一个基本抽象类。

代码如下:

    public ref class PDFPrinter
    {
    internal:
        int index;
        SPDFPrinter* p;
    public:
        PDFPrinter();
        virtual property int HorizontalDPI { int get(){ return 72; } }
        virtual property int VerticalDPI { int get(){ return 72; } }
        virtual property bool UseMediaBox { bool get(){ return true; } }
        virtual property bool CropPage { bool get(){ return true; } }
        virtual property Second::PDF::PageRotation PageRotation 
            { Second::PDF::PageRotation get() 
              {return Second::PDF::PageRotation::Rotate0; } 
            }


        virtual property bool IsUpsideDownCoordinateSystem { bool get() = 0; }
        virtual property bool CanUseDrawChar { bool get() = 0; }
        virtual property bool IsType3CharsInterpretted { bool get() = 0; }
        virtual property bool CanUseTilingPatternFill { bool get() = 0; }
        virtual property bool CanUseShadedFills{ bool get() = 0; }
        virtual property bool CanUseDrawForm{ bool get() = 0; }
        virtual property bool CanResolveText { bool get() = 0; }
        virtual property bool CanCreateAntialiasedVectors { bool get() = 0; }

        virtual bool CanDrawPageSlice(PDFPage page, 
          System::Drawing::PointF resolution, Second::PDF::PageRotation rotation,
          System::Drawing::Rectangle slice, bool useMediaBox, 
          bool cropEnabled, bool isPrinting) = 0;

    };

这是元数据:

using System;
using System.Drawing;

namespace Second.PDF
{
    public abstract class PDFPrinter
    {
        public PDFPrinter();

        public abstract bool CanCreateAntialiasedVectors { get; }
        public abstract bool CanResolveText { get; }
        public abstract bool CanUseDrawChar { get; }
        public abstract bool CanUseDrawForm { get; }
        public abstract bool CanUseShadedFills { get; }
        public abstract bool CanUseTilingPatternFill { get; }
        public virtual bool CropPage { get; }
        public virtual int HorizontalDPI { get; }
        public abstract bool IsType3CharsInterpretted { get; }
        public abstract bool IsUpsideDownCoordinateSystem { get; }
        public virtual PageRotation PageRotation { get; }
        public virtual bool UseMediaBox { get; }
        public virtual int VerticalDPI { get; }

        public abstract bool CanDrawPageSlice(PDFPage page, PointF resolution,
        PageRotation rotation, Rectangle slice, bool useMediaBox, 
        bool cropEnabled, bool isPrinting);
    }
}

当我尝试像这样在 c# 中使用这个类时:

class Printer : PDFPrinter
{
    public override bool CanCreateAntialiasedVectors
    {
        get { throw new NotImplementedException(); }
    }

    public override bool CanResolveText
    {
        get { throw new NotImplementedException(); }
    }

    public override bool CanUseDrawChar
    {
        get { throw new NotImplementedException(); }
    }

    public override bool CanUseDrawForm
    {
        get { throw new NotImplementedException(); }
    }

    public override bool CanUseShadedFills
    {
        get { throw new NotImplementedException(); }
    }

    public override bool CanUseTilingPatternFill
    {
        get { throw new NotImplementedException(); }
    }

    public override bool IsType3CharsInterpretted
    {
        get { throw new NotImplementedException(); }
    }

    public override bool IsUpsideDownCoordinateSystem
    {
        get { throw new NotImplementedException(); }
    }


    public override bool CanDrawPageSlice(PDFPage page, 
    System.Drawing.PointF resolution, PageRotation rotation, 
    System.Drawing.Rectangle slice, bool useMediaBox, 
    bool cropEnabled, bool isPrinting)
    {
        throw new NotImplementedException();
    }
}

我收到这个奇怪的错误:

错误 1 ​​'Second.PDFLib.CSharp.Test.Printer' 不实现继承的抽象 成员 'Second.PDF.PDFPrinter.CanDrawPageSlice()' C:\Projects\Visual Studio\test\Second.PDFLib.CSharp.Test\Program.cs 8 11 Second.PDFLib.CSharp.Test

错误 2 'Second.PDFLib.CSharp.Test.Printer.CanDrawPageSlice(Second.PDF.PDFPage, System.Drawing.PointF, Second.PDF.PageRotation, System.Drawing.Rectangle,布尔,布尔, bool)': 没有找到合适的方法 覆盖 C:\Projects\Visual Studio\test\Second.PDFLib.CSharp.Test\Program.cs 51 30 Second.PDFLib.CSharp.Test

你有什么想法来解决这个错误吗?

谢谢

P.S:只有这个抽象方法(CanDrawPageSlice)会产生错误。没有这个方法是没有问题的。

编辑

耻辱!耻辱!耻辱!真丢人! :) 那完全是我的错!

我想通了..问题来源是c++类

我忘记在此处使用顶级运算符 (^)(PDFPage 页面)

virtual bool CanDrawPageSlice(PDFPage page, 
  System::Drawing::PointF resolution, Second::PDF::PageRotation rotation,
  System::Drawing::Rectangle slice, bool useMediaBox, 
  bool cropEnabled, bool isPrinting) = 0;

应该是这样的:

virtual bool CanDrawPageSlice(PDFPage^ page, 
  System::Drawing::PointF resolution, Second::PDF::PageRotation rotation,
  System::Drawing::Rectangle slice, bool useMediaBox, 
  bool cropEnabled, bool isPrinting) = 0;

【问题讨论】:

  • 您是通过键入 override 并让 VS 填充参数列表来生成覆盖,还是您自己键入?基类是否有可能为前 4 个参数选择不同的类?
  • 刚刚使用了“实现抽象类'PDFPrinter'”选项..我的意思是它是自动生成的。
  • 获取您的解决方案,回答您自己的问题,然后选择它作为正确答案。可能看起来有点奇怪或俗气,但这是这里的标准程序。
  • “您可以在 2 天内接受自己的答案”.. :))

标签: c# inheritance c++-cli overriding abstract


【解决方案1】:

耻辱!耻辱!耻辱!真丢人! :) 那完全是我的错!

我想通了..问题来源是c++类

我忘记在此处使用顶级运算符 (^)(PDFPage 页面)

virtual bool CanDrawPageSlice(PDFPage page, 
  System::Drawing::PointF resolution, Second::PDF::PageRotation rotation,
  System::Drawing::Rectangle slice, bool useMediaBox, 
  bool cropEnabled, bool isPrinting) = 0;

应该是这样的:

virtual bool CanDrawPageSlice(PDFPage^ page, 
  System::Drawing::PointF resolution, Second::PDF::PageRotation rotation,
  System::Drawing::Rectangle slice, bool useMediaBox, 
  bool cropEnabled, bool isPrinting) = 0;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-23
    • 2016-11-08
    • 1970-01-01
    • 2013-05-30
    • 1970-01-01
    相关资源
    最近更新 更多