如何使用非默认构造函数创建本地对象?

时间:2019-04-26 21:32:36

标签: c++

我已经主要使用C#和Python编程了几年了,幸运的是,C ++远远落后了。但是,现在我回到它进行微不足道的练习,发现我已经忘记了远远不应该的事情。

我在头文件中定义了以下类:


    // ReportsLib.h

    #pragma once
    #include "std_unicode.h"
    #include "comstring.h"
    #include "reportslib_export.h"

    class _REPORTSLIB_CLASS_EXPORT CapsReport
    {
    private:
        CCOMString m_ReportFile;

    public:
        // TODO: Add your methods for this class here.
        CapsReport() {}
        CapsReport(const CCOMString& reportFileName) {}
        void Display() {}
        void Print() {}
    };

我想这样使用非默认构造函数:


    void CCapsApp::PreviewReport(CString ReportName, CString Title)
    {
    #ifndef NO_REPORTS
        CRXReport*  pReport;
        CCOMString reportName(LPCTSTR ReportName);
        // CapsReport newReport(reportName);

        try {
            pReport = printEngine.OpenReport((LPCTSTR)ReportName);
            if ( pReport != NULL ) 
                pReport->PrintPreview((LPCTSTR)Title);
            else
                AfxMessageBox(_T("Report not found"), MB_OK);
        } catch (CRXReportException *Error) {
            AfxMessageBox(Error->Message, MB_OK);
            Error->Delete();
        } catch (CException *pEx) {
            pEx->ReportError();
            pEx->Delete();
        }
    #endif
    }

当我尝试创建名为reportName的CCOMString对象时收到警告:“未调用原型函数(是否打算使用变量定义?”是的,它是有意的,但是我该怎么做?

1 个答案:

答案 0 :(得分:0)

更改

CCOMString reportName(LPCTSTR ReportName);

CCOMString reportName(ReportName);

原始行被编译为名为reportName的函数的函数声明。

相关问题