Reputation: 6633
I am trying to compile the example from QtSocketIO called EchoClient.
However when I try to compile using MSVC2013, I get the following error in the echoclient.cpp
1> echoclient.cpp
1>echoclient.cpp(7): error C2010: '.' : unexpected in macro formal parameter list
The code looks like this where I have put as comments the errors in each line
#include "echoclient.h"
#include "qsocketioclient.h"
#include <QtCore/QJsonObject>
#include <QtCore/QJsonArray>
#include <QtCore/QDebug>
#define function(args...) [=](args) // Error expected a ')'
void EchoClient::connected(QString endpoint)
{
qDebug() << "Connected to endpoint" << endpoint;
m_client.emitMessage("event with 2 arguments",
QVariantList() << 1 << QStringLiteral("Hello socket.io"),
function(QJsonArray returnValue) { // Error expected an expression
qDebug() << "Got reply from event with 2 arguments:" << returnValue;
});
m_client.emitMessage("event with a json object",
QVariantMap({ {"number", 1}, { QStringLiteral("message"),
QStringLiteral("Hello socket.io")}}),
function(QJsonArray returnValue) { // Error expected an expression
qDebug() << "Got reply from event with a json object:" << returnValue;
});
m_client.on("event from server", function(QJsonArray data) { // Error expected an expression
qDebug() << "Got event from server with data" << data;
});
}
Can someone explain to me what does that macro is doing? Is there a way to solve the error?
Upvotes: 0
Views: 323
Reputation: 4637
The macro is making a lambda look sort of like an ordinary function declaration. The reason it doesn't work is because, as mentioned in the comments, #define function(args...) [=](args)
isn't correct. Changing it to #define function(...) [=](__VA_ARGS__)
will work.
Upvotes: 1