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

时间:2013-05-28 20:23:09

标签: windows compiler-errors windows-phone-8 directx c++-cx

我正在尝试通过一个小型的Windows手机应用来学习C ++。目前我只是按照教程来掌握Windows手机的开发。但是,在尝试构建代码时遇到了模糊的信号错误。我已经习惯了与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;
}

2 个答案:

答案 0 :(得分:3)

您正在使用大量命名空间。看来

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();

答案 1 :(得分:0)

我在WP8 SDK项目中遇到了同样的问题。

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

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

而不是

IAsyncOperation<String^> ^CreateSampleData();