在尝试编译我的c ++项目时,编译器退出并在ZMQ的poller.ipp中出错。我做错了什么,我需要额外的编译器标志吗?
我使用brew install czmqpp
系统:Mac OSX 10.11.5
当我尝试使用以下命令进行编译时,这是输出:
> gcc -Wall -o HardwareHub HardwareHub.cpp
In file included from HardwareHub.cpp:4:
In file included from ./ZMQCommunicator.h:3:
In file included from /usr/local/include/czmq++/czmqpp.hpp:28:
In file included from /usr/local/include/czmq++/poller.hpp:48:
/usr/local/include/czmq++/impl/poller.ipp:29:19: error: expected expression
auto unmask = [](socket& s)
^
1 error generated.
提前谢谢
答案 0 :(得分:1)
您需要使用c ++编译器,而不是c编译器:
using System; using System.Collections.Generic; using System.Linq; using System.Reflection; using Autofac; public interface ICommand { } public class CommandOne : ICommand { } public class CommandTwo : ICommand { } public interface ICommandHandler<T> where T : ICommand { void Handle(T arg); } public class CommandOneHandler : ICommandHandler<CommandOne> { public void Handle(CommandOne arg) { } } public class CommandTwoHandler : ICommandHandler<CommandTwo> { public void Handle(CommandTwo arg) { } } public interface ICommandBus { IEnumerable<object> Handlers { get; } void RegisterHandler<TCommand, THandler>(THandler handler) where THandler : ICommandHandler<TCommand> where TCommand : ICommand; } public class CommandBus : ICommandBus { private readonly List<object> _handlers = new List<object>(); public IEnumerable<object> Handlers { get { return this._handlers; } } public void RegisterHandler<TCommand, THandler>(THandler handler) where THandler : ICommandHandler<TCommand> where TCommand : ICommand { this._handlers.Add(handler); } } var builder = new ContainerBuilder(); // Track the list of registered command types. var registeredHandlerTypes = new List<Type>(); builder.RegisterAssemblyTypes(Assembly.GetExecutingAssembly()) .AsClosedTypesOf(typeof(ICommandHandler<>)) .OnRegistered(e => registeredHandlerTypes.Add(e.ComponentRegistration.Activator.LimitType)); // Initialize the bus by registering handlers on activating. builder.RegisterType<CommandBus>() .As<ICommandBus>() .OnActivating(e => { foreach(var handlerType in registeredHandlerTypes) { // Due to the generic method, some crazy reflection happens. // First, get ICommandHandler<T> interface. var handlerInterfaceType = handlerType.GetInterface("ICommandHandler`1"); // Grab the <T> from the ICommandHandler<T>. var commandType = handlerInterfaceType.GetGenericArguments()[0]; // Build the closed generic version of RegisterHandler<TCommand, THandler>. var registerMethod = typeof(ICommandBus).GetMethod("RegisterHandler").MakeGenericMethod(commandType, handlerType); // Call the closed generic RegisterHandler<TCommand, THandler> to register the handler. registerMethod.Invoke(e.Instance, new object[] { e.Context.Resolve(handlerInterfaceType) }); } }) .SingleInstance(); var container = builder.Build(); using(var scope = container.BeginLifetimeScope()) { var bus = scope.Resolve<ICommandBus>(); foreach(var t in bus.Handlers) { // List the handler types registered. Console.WriteLine(t.GetType()); } }
应该是
> gcc -Wall -o HardwareHub HardwareHub.cpp
如果您当前安装的GCC版本不支持当前的c ++标准,请使用
> g++ -Wall -o HardwareHub HardwareHub.cpp