C++ visualc&x2B+;打印文档错误

C++ visualc&x2B+;打印文档错误,c++,visual-studio,c++-cli,C++,Visual Studio,C++ Cli,我用以下代码调用了printDocument操作和buttonClick事件: private: System::Void btnPrint_Click(System::Object^ sender, System::EventArgs^ e) { PrintDialog prdl = gcnew PrintDialog(); printDialog1->Document = printDocument1; printDialog1-&g

我用以下代码调用了printDocument操作和buttonClick事件:

private: System::Void btnPrint_Click(System::Object^  sender, System::EventArgs^  e) {
    PrintDialog prdl = gcnew PrintDialog();            
    printDialog1->Document = printDocument1;
    printDialog1->UseEXDialog = true;                 
    printDocument1->Print();
         }
我基本上有一个数据网格视图组件、一个打印对话框组件、一个打印文档组件和一个按钮。单击按钮后,我尝试使用该代码显示一个打印对话框,然后尝试在页面的结尾处打印表格,但是我遇到了以下错误:

c:\documents and settings\stefan.mona-h6h4kpujnf\desktop\centralizator_debite\centralizator_debite\Form1.h(212): error C3673: 'System::Windows::Forms::PrintDialog' : class does not have a copy-constructor

我正在使用Visual studio 2010 Windows窗体应用程序。我有我需要的每一个组件(见上文),我不知道如何解决这个错误。

我不知道什么是
gcnew
,但是如果你打算写

PrintDialog prdl = new PrintDialog(); 
试试这个

PrintDialog prdl(); 
区别在于,在第一种情况下,您在堆上创建一个对象,并尝试从指针初始化

编辑:刚在谷歌上搜索到这实际上是C++/CLI,而不是纯C++

它不起作用的原因是: 没有复制构造函数,这意味着您可以:

 mytype uniqueID() //build a unique id from scratch
但你不能

 mytype uniqueID = someOtherID; //create a unique id by copying.
<> P> ALL,在我的C++背景下,在上下文中使用<代码> GCnPrimtDeDeCudio()/代码>我有点不清楚,但我最好的猜测是它如下:

  • 使用自动内存管理在堆上创建对象
  • 返回一个句柄(http://en.wikipedia.org/wiki/C%2B%2B/CLI#Handles)
  • 所以也许你也想试试这个

    PrintDialog^ prdl = gcnew PrintDialog(); 
    
    区别如下:

    PrintDialog prdl();
    
    创建一个局部变量,它将在上下文(函数)离开后消失

    在垃圾回收所管理的heab上创建一个对象。这意味着你可以做到这一点

     PrintDialog^ get() { return gcnew PrintDialog; }
    
     main() {
        ...
        PrintDialog^ dialog = get();
        //use dialog
     }
    

    如果使用第一种方法,对话框将停止运行,
    get()
    返回的那一刻,而在第二种情况下,它将一直存在,直到垃圾收集器运行并确定无法再访问它,从而删除它以释放内存。

    使用new给了我另一个错误,告诉我使用gcnew。
    gcnew
    是语言的一部分。
     PrintDialog^ get() { return gcnew PrintDialog; }
    
     main() {
        ...
        PrintDialog^ dialog = get();
        //use dialog
     }