What causes ambiguous symbol errors? C++

14,346

You're using a lot of namespaces. It would appear that

EventRegistrationToken

Is defined in

Windows::Foundation; //windows.winmd

And again in eventtoken.h. Not sure which namespace this would apply to, could be global. Ditch the

using namespace Windows::Foundation;

and then you can access the respective implementations like this:

//eventtoken.h impl
EventRegistrationToken();

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

Although it looks like you don't need this function, so it may not matter, this is just for example, and for how... since you need to remove this namespace, how you can now access the other members of this namespace.

I imagine you coud safely do this as well, though I don't necessarily recommend it:

using namespace Windows;
Foundation::EventRegistrationToken();
Share:
14,346
Pectus Excavatum
Author by

Pectus Excavatum

Updated on June 04, 2022

Comments

  • Pectus Excavatum
    Pectus Excavatum almost 2 years

    I am trying to learn C++ by doing a small windows phone app. Currently I am just following a tutorial to get to grips with developing for the windows phone. However, I have encountered a ambiguous signal error when trying to build the code. I am used to the niceties associated with Java and am a bit lost as to what could be causing this error. The error dump I get is:

    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'
    

    The code is attached below - sorry for giving the whole file, but I literally dont know where to start. Any help would be greatly appreciated.

    Thanks

    #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;
    }