求助: 多重继承两个基类有同名函数
Document 是 _Document和DocumentEvent2_Event的派生类。_Document中有一个函数 Microsoft::Office::Interop::Word::_Document::Close([System::Object^], [System::Object^], [System::Object^])
DocumentEvent2_Event中有一个事件响应函数Microsoft::Office::Interop::Word::DocumentEvents2_Event::Close
造成对象wordDoc 对“Close”的访问不明确
可以是基 "Microsoft::Office::Interop::Word::_Document" 中的 "Close"
也可以是基 "Microsoft::Office::Interop::Word::DocumentEvents2_Event" 中的 "Close"
编译器错误 C3278“Microsoft::Office::Interop::Word::_Document::Close”接口或纯方法的直接调用将在运行时失败
编译器错误 C3278 微软查询
接口或纯方法“method”的直接调用将在运行时失败
注解
对接口方法或纯方法进行了调用,这是不允许的。
示例
以下示例生成 C3278:
程序代码:
// C3278_2.cpp // compile with: /clr using namespace System; interface class I { void vmf(); }; public ref class C: public I { public: void vmf() { Console::WriteLine( "In C::vmf()" ); I::vmf(); // C3278 } }; int main() { C^ pC = gcnew C; pC->vmf(); }
还是,不明白,代码应该如何修改。。。。
我的程序代码
程序代码:
using namespace System; using namespace System::IO; using namespace System::Reflection; namespace MSWord = Microsoft::Office::Interop::Word; int main(array<System::String^>^ args) { Object^ path; //文件路径变量 String^ strContent; //文本内容变量 MSWord::Application^ wordApp; //Word应用程序变量 MSWord::Document^ wordDoc; //Word文档变量 array<String^>^ WriteDocumen = { "去年今日此门中,\n","人面桃花相映红。\n" ,"人面不知何处去,\n", "桃花依旧笑春风。" }; path = "C:\\Users\\Administrator\\Desktop\\测试" + DateTime::Now.ToString("yyyyMMddHHmmss") + ".doc"; wordApp = gcnew MSWord::ApplicationClass(); //初始化 wordApp->Visible = true;//使文档可见 //由于使用的是COM库,因此有许多变量需要用Missing.Value代替 Object^ Nothing = Missing::Value; wordDoc = wordApp->Documents->Add(Nothing, Nothing, Nothing, Nothing);//ref Nothing); //行间距与缩进、文本字体、字号 wordApp->Selection->ParagraphFormat->LineSpacing = 16;//设置文档的行间距 wordApp->Selection->ParagraphFormat->FirstLineIndent = 0;//首行缩进的长度 //写入普通文本 strContent = "题都城南庄\n"; wordDoc->Paragraphs->Last->Range->Font->Size = 22; wordDoc->Paragraphs->Last->Range->Font->Name = "方正小标宋简体"; wordDoc->Paragraphs->Last->Range->Text = strContent; wordApp->Selection->ParagraphFormat->Alignment = MSWord::WdParagraphAlignment::wdAlignParagraphCenter; Object^ unite = MSWord::WdUnits::wdStory; wordApp->Selection->ParagraphFormat->FirstLineIndent = 10;//设置首行缩进的长度 for each (auto i in WriteDocumen) { wordApp->Selection->EndKey(unite, Nothing);//将光标移到文本末尾 wordDoc->Paragraphs->Last->Range->Font->Name = "华文行楷"; wordDoc->Paragraphs->Last->Range->Font->Size = 48; wordDoc->Paragraphs->Last->Range->Text = i; wordApp->Selection->ParagraphFormat->Alignment = MSWord::WdParagraphAlignment::wdAlignParagraphCenter; } wordApp->Selection->EndKey(unite, Nothing); //将光标移动到文档末尾 //WdSaveFormat为Word 2003文档的保存格式 Object^ format = MSWord::WdSaveFormat::wdFormatDocument;// office 2007就是wdFormatDocumentDefault //将wordDoc文档对象的内容保存为DOCX文档 wordDoc->SaveAs(path, format, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing); Object^ saveChanges = MSWord::WdSaveOptions::wdSaveChanges; Object^ originalFormat = Type::Missing; Object^ routeDocument = Type::Missing; //wordDoc->_Document::Close(saveChanges, originalFormat, routeDocument); }