c#的VC ++ / CLI抽象方法实现问题

时间:2010-12-15 07:56:43

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

我正在开发一个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,bool,   bool)':找不到合适的方法   覆盖C:\ Projects \ Visual   Studio \ test \ Second.PDFLib.CSharp.Test \ Program.cs 51 30 Second.PDFLib.CSharp.Test

你有任何想法来解决这个错误吗?

谢谢

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

修改

耻!耻辱!耻辱!对我感到羞耻! :)这完全是我的错误!

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

我忘了在这里使用顶级操作员(^)(PDF页面)

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;

1 个答案:

答案 0 :(得分:1)

耻!耻辱!耻辱!对我感到羞耻! :)这完全是我的错误!

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

我忘了在这里使用顶级操作员(^)(PDF页面)

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;