草庐IT

windows - 什么导致歧义符号错误? C++

coder 2024-06-19 原文

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

关于windows - 什么导致歧义符号错误? C++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16800831/

有关windows - 什么导致歧义符号错误? C++的更多相关文章

  1. ruby - 为什么我可以在 Ruby 中使用 Object#send 访问私有(private)/ protected 方法? - 2

    类classAprivatedeffooputs:fooendpublicdefbarputs:barendprivatedefzimputs:zimendprotecteddefdibputs:dibendendA的实例a=A.new测试a.foorescueputs:faila.barrescueputs:faila.zimrescueputs:faila.dibrescueputs:faila.gazrescueputs:fail测试输出failbarfailfailfail.发送测试[:foo,:bar,:zim,:dib,:gaz].each{|m|a.send(m)resc

  2. ruby - 在 Ruby 程序执行时阻止 Windows 7 PC 进入休眠状态 - 2

    我需要在客户计算机上运行Ruby应用程序。通常需要几天才能完成(复制大备份文件)。问题是如果启用sleep,它会中断应用程序。否则,计算机将持续运行数周,直到我下次访问为止。有什么方法可以防止执行期间休眠并让Windows在执行后休眠吗?欢迎任何疯狂的想法;-) 最佳答案 Here建议使用SetThreadExecutionStateWinAPI函数,使应用程序能够通知系统它正在使用中,从而防止系统在应用程序运行时进入休眠状态或关闭显示。像这样的东西:require'Win32API'ES_AWAYMODE_REQUIRED=0x0

  3. ruby-on-rails - Rails - 子类化模型的设计模式是什么? - 2

    我有一个模型:classItem项目有一个属性“商店”基于存储的值,我希望Item对象对特定方法具有不同的行为。Rails中是否有针对此的通用设计模式?如果方法中没有大的if-else语句,这是如何干净利落地完成的? 最佳答案 通常通过Single-TableInheritance. 关于ruby-on-rails-Rails-子类化模型的设计模式是什么?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.co

  4. ruby-on-rails - Rails 常用字符串(用于通知和错误信息等) - 2

    大约一年前,我决定确保每个包含非唯一文本的Flash通知都将从模块中的方法中获取文本。我这样做的最初原因是为了避免一遍又一遍地输入相同的字符串。如果我想更改措辞,我可以在一个地方轻松完成,而且一遍又一遍地重复同一件事而出现拼写错误的可能性也会降低。我最终得到的是这样的:moduleMessagesdefformat_error_messages(errors)errors.map{|attribute,message|"Error:#{attribute.to_s.titleize}#{message}."}enddeferror_message_could_not_find(obje

  5. ruby - 什么是填充的 Base64 编码字符串以及如何在 ruby​​ 中生成它们? - 2

    我正在使用的第三方API的文档状态:"[O]urAPIonlyacceptspaddedBase64encodedstrings."什么是“填充的Base64编码字符串”以及如何在Ruby中生成它们。下面的代码是我第一次尝试创建转换为Base64的JSON格式数据。xa=Base64.encode64(a.to_json) 最佳答案 他们说的padding其实就是Base64本身的一部分。它是末尾的“=”和“==”。Base64将3个字节的数据包编码为4个编码字符。所以如果你的输入数据有长度n和n%3=1=>"=="末尾用于填充n%

  6. ruby - 解析 RDFa、微数据等的最佳方式是什么,使用统一的模式/词汇(例如 schema.org)存储和显示信息 - 2

    我主要使用Ruby来执行此操作,但到目前为止我的攻击计划如下:使用gemsrdf、rdf-rdfa和rdf-microdata或mida来解析给定任何URI的数据。我认为最好映射到像schema.org这样的统一模式,例如使用这个yaml文件,它试图描述数据词汇表和opengraph到schema.org之间的转换:#SchemaXtoschema.orgconversion#data-vocabularyDV:name:namestreet-address:streetAddressregion:addressRegionlocality:addressLocalityphoto:i

  7. ruby - 为什么 4.1%2 使用 Ruby 返回 0.0999999999999996?但是 4.2%2==0.2 - 2

    为什么4.1%2返回0.0999999999999996?但是4.2%2==0.2。 最佳答案 参见此处:WhatEveryProgrammerShouldKnowAboutFloating-PointArithmetic实数是无限的。计算机使用的位数有限(今天是32位、64位)。因此计算机进行的浮点运算不能代表所有的实数。0.1是这些数字之一。请注意,这不是与Ruby相关的问题,而是与所有编程语言相关的问题,因为它来自计算机表示实数的方式。 关于ruby-为什么4.1%2使用Ruby返

  8. ruby-on-rails - 如何优雅地重启 thin + nginx? - 2

    我的瘦服务器配置了nginx,我的ROR应用程序正在它们上运行。在我发布代码更新时运行thinrestart会给我的应用程序带来一些停机时间。我试图弄清楚如何优雅地重启正在运行的Thin实例,但找不到好的解决方案。有没有人能做到这一点? 最佳答案 #Restartjustthethinserverdescribedbythatconfigsudothin-C/etc/thin/mysite.ymlrestartNginx将继续运行并代理请求。如果您将Nginx设置为使用多个上游服务器,例如server{listen80;server

  9. ruby - ruby 中的 TOPLEVEL_BINDING 是什么? - 2

    它不等于主线程的binding,这个toplevel作用域是什么?此作用域与主线程中的binding有何不同?>ruby-e'putsTOPLEVEL_BINDING===binding'false 最佳答案 事实是,TOPLEVEL_BINDING始终引用Binding的预定义全局实例,而Kernel#binding创建的新实例>Binding每次封装当前执行上下文。在顶层,它们都包含相同的绑定(bind),但它们不是同一个对象,您无法使用==或===测试它们的绑定(bind)相等性。putsTOPLEVEL_BINDINGput

  10. ruby - Infinity 和 NaN 的类型是什么? - 2

    我可以得到Infinity和NaNn=9.0/0#=>Infinityn.class#=>Floatm=0/0.0#=>NaNm.class#=>Float但是当我想直接访问Infinity或NaN时:Infinity#=>uninitializedconstantInfinity(NameError)NaN#=>uninitializedconstantNaN(NameError)什么是Infinity和NaN?它们是对象、关键字还是其他东西? 最佳答案 您看到打印为Infinity和NaN的只是Float类的两个特殊实例的字符串

随机推荐