2013-05-28 78 views
1

我想通過做一個小型的Windows手機應用程序來學習C++。目前我只是遵循一個教程來掌握開發的Windows手機。但是,在嘗試構建代碼時遇到了模糊的信號錯誤。我習慣了與Java相關的細節,並且對於可能導致此錯誤的內容有點遺憾。錯誤轉儲我得到的是:什麼導致模糊的符號錯誤? C++

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; 
} 
+0

這很可能是由於您使用的命名空間(污染全局命名空間)的量引起的嘗試範圍用它們來代替。 –

+0

命名空間的存在可以避免這種問題。把所有這些「使用」聲明糅合在一起,就會破壞它們的目的。不要這樣做。順便說一下,'ref new'和'object ^'東西不是C++。 –

+0

這是C++/CLI。不幸。看到類似的問題與建議,可以幫助你-http://stackoverflow.com/questions/15767146/including-windows-storage-streams-h – SChepurin

回答

3

您使用了大量的命名空間。這樣看來,

EventRegistrationToken 

Windows::Foundation; //windows.winmd 

定義並再次eventtoken.h。不知道這將適用於哪個名稱空間,可能是全局的。溝

using namespace Windows::Foundation; 

然後你就可以訪問相應的實施方案是這樣的:

//eventtoken.h impl 
EventRegistrationToken(); 

//the one in Foundation namespace: 
Windows::Foundation::EventRegistrationToken(); 

雖然看起來你不需要這個功能,因此它可能並不重要,這只是舉例,以及如何...因爲你需要刪除這個命名空間,你現在如何訪問這個命名空間的其他成員。

我想你coud安全地做到這一點爲好,雖然我並不推薦它:

using namespace Windows; 
Foundation::EventRegistrationToken(); 
0

我只用WP8 SDK的項目同樣的問題。

修復:使用Windows :: Foundation從.h文件中刪除並使用完整的命名空間來調用您的對象類型。

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

代替

IAsyncOperation<String^> ^CreateSampleData(); 
相關問題