什么导致模糊的符号错误? C ++

我正在尝试通过做一个小型的Windows手机应用程序来学习C ++。 目前我只是按照教程来掌握开发的Windows手机。 但是,在尝试构build代码时遇到了模糊的信号错误。 我已经习惯了与Java相关的细节,并且对于可能导致这个错误的东西有点遗憾。 我得到的错误转储是:

1>c:\program files (x86)\windows phone kits\8.0\include\wrl\event.h(740): error C2872: 'EventRegistrationToken' : ambiguous symbol 1> could be 'c:\program files (x86)\windows phone kits\8.0\include\eventtoken.h(51) : EventRegistrationToken' 1> or 'c:\program files (x86)\windows phone kits\8.0\windows metadata\windows.winmd : Windows::Foundation::EventRegistrationToken' 1> c:\program files (x86)\windows phone kits\8.0\include\wrl\event.h(1035) : see reference to class template instantiation 'Microsoft::WRL::EventSource<TDelegateInterface>' being compiled 1>c:\program files (x86)\windows phone kits\8.0\include\wrl\event.h(814): error C2872: 'EventRegistrationToken' : ambiguous symbol 1> could be 'c:\program files (x86)\windows phone kits\8.0\include\eventtoken.h(51) : EventRegistrationToken' 1> or 'c:\program files (x86)\windows phone kits\8.0\windows metadata\windows.winmd : Windows::Foundation::EventRegistrationToken' 

代码附在下面 – 抱歉给整个文件,但我实际上不知道从哪里开始。 任何帮助将不胜感激。

谢谢

 #include "pch.h" #include "WindowsPhoneGame.h" #include "BasicTimer.h" //#include <string.h> #include <sstream> //using namespace std; using namespace Windows::ApplicationModel; using namespace Windows::ApplicationModel::Core; using namespace Windows::ApplicationModel::Activation; using namespace Windows::UI::Core; using namespace Windows::System; using namespace Windows::Foundation; using namespace Windows::Graphics::Display; using namespace concurrency; WindowsPhoneGame::WindowsPhoneGame() : m_windowClosed(false), m_windowVisible(true) { } void WindowsPhoneGame::Initialize(CoreApplicationView^ applicationView) { applicationView->Activated += ref new TypedEventHandler<CoreApplicationView^, IActivatedEventArgs^>(this, &WindowsPhoneGame::OnActivated); CoreApplication::Suspending += ref new EventHandler<SuspendingEventArgs^>(this, &WindowsPhoneGame::OnSuspending); CoreApplication::Resuming += ref new EventHandler<Platform::Object^>(this, &WindowsPhoneGame::OnResuming); m_renderer = ref new Renderer(); } void WindowsPhoneGame::SetWindow(CoreWindow^ window) { window->VisibilityChanged += ref new TypedEventHandler<CoreWindow^, VisibilityChangedEventArgs^>(this, &WindowsPhoneGame::OnVisibilityChanged); window->Closed += ref new TypedEventHandler<CoreWindow^, CoreWindowEventArgs^>(this, &WindowsPhoneGame::OnWindowClosed); window->PointerPressed += ref new TypedEventHandler<CoreWindow^, PointerEventArgs^>(this, &WindowsPhoneGame::OnPointerPressed); window->PointerMoved += ref new TypedEventHandler<CoreWindow^, PointerEventArgs^>(this, &WindowsPhoneGame::OnPointerMoved); window->PointerReleased += ref new TypedEventHandler<CoreWindow^, PointerEventArgs^>(this, &WindowsPhoneGame::OnPointerReleased); m_renderer->Initialize(CoreWindow::GetForCurrentThread()); } void WindowsPhoneGame::Load(Platform::String^ entryPoint) { } void WindowsPhoneGame::Run() { BasicTimer^ timer = ref new BasicTimer(); while (!m_windowClosed) { if (m_windowVisible) { timer->Update(); CoreWindow::GetForCurrentThread()->Dispatcher- >ProcessEvents(CoreProcessEventsOption::ProcessAllIfPresent); m_renderer->Update(timer->Total, timer->Delta); m_renderer->Render(); m_renderer->Present(); // This call is synchronized to the display frame rate. } else { CoreWindow::GetForCurrentThread()->Dispatcher->ProcessEvents(CoreProcessEventsOption::ProcessOneAndAllPending); } } } void WindowsPhoneGame::Uninitialize() { } void WindowsPhoneGame::OnVisibilityChanged(CoreWindow^ sender, VisibilityChangedEventArgs^ args) { m_windowVisible = args->Visible; } void WindowsPhoneGame::OnWindowClosed(CoreWindow^ sender, CoreWindowEventArgs^ args) { m_windowClosed = true; } void WindowsPhoneGame::OnPointerPressed(CoreWindow^ sender, PointerEventArgs^ args) { ostringstream sstream; sstream << "Pressed at: " << "X: " << args->CurrentPoint->Position.X << " Y: " << args->CurrentPoint->Position.Y << "\n"; string s = sstream.str(); OutputDebugStringA(s.c_str()); } void WindowsPhoneGame::OnPointerMoved(CoreWindow^ sender, PointerEventArgs^ args) { ostringstream sstream; sstream << "Moved at: " << "X: " << args->CurrentPoint->Position.X << " Y: " << args->CurrentPoint->Position.Y << "\n"; string s = sstream.str(); OutputDebugStringA(s.c_str()); } void WindowsPhoneGame::OnPointerReleased(CoreWindow^ sender, PointerEventArgs^ args) { ostringstream sstream; sstream << "Released at: " << "X: " << args->CurrentPoint->Position.X << " Y: " << args->CurrentPoint->Position.Y << "\n"; string s = sstream.str(); OutputDebugStringA(s.c_str()); } void WindowsPhoneGame::OnActivated(CoreApplicationView^ applicationView, IActivatedEventArgs^ args) { CoreWindow::GetForCurrentThread()->Activate(); } void WindowsPhoneGame::OnSuspending(Platform::Object^ sender, SuspendingEventArgs^ args) { // Save app state asynchronously after requesting a deferral. Holding a deferral // indicates that the application is busy performing suspending operations. Be // aware that a deferral may not be held indefinitely. After about five seconds, // the app will be forced to exit. SuspendingDeferral^ deferral = args->SuspendingOperation->GetDeferral(); m_renderer->ReleaseResourcesForSuspending(); create_task([this, deferral]() { // Insert your code here. deferral->Complete(); }); } void WindowsPhoneGame::OnResuming(Platform::Object^ sender, Platform::Object^ args) { // Restore any data or state that was unloaded on suspend. By default, data // and state are persisted when resuming from suspend. Note that this event // does not occur if the app was previously terminated. m_renderer->CreateWindowSizeDependentResources(); } IFrameworkView^ Direct3DApplicationSource::CreateView() { return ref new WindowsPhoneGame(); } [Platform::MTAThread] int main(Platform::Array<Platform::String^>^) { auto direct3DApplicationSource = ref new Direct3DApplicationSource(); CoreApplication::Run(direct3DApplicationSource); return 0; } 

你正在使用很多命名空间。 这似乎是

 EventRegistrationToken 

被定义在

 Windows::Foundation; //windows.winmd 

再次在eventtoken.h中。 不知道这将适用于哪个命名空间,可能是全球性的。 沟

 using namespace Windows::Foundation; 

然后你可以像这样访问相应的实现:

 //eventtoken.h impl EventRegistrationToken(); //the one in Foundation namespace: Windows::Foundation::EventRegistrationToken(); 

虽然它看起来像你不需要这个函数,所以它可能并不重要,这只是例如,以及如何…因为你需要删除这个名字空间,你现在如何访问这个名字空间的其他成员。

我想你也可以安全地做到这一点,虽然我不一定推荐它:

 using namespace Windows; Foundation::EventRegistrationToken(); 

我只有WP8 SDK项目有同样的问题。

修复:从.h文件中删除使用Windows :: Foundation,并使用完整的名称空间来调用您的对象类型。

 Windows::Foundation::IAsyncOperation<String^> ^Blah(); 

代替

 IAsyncOperation<String^> ^CreateSampleData();