Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【结构体中调用XTOSTRUCT失败】 #2

Closed
jigetage opened this issue Nov 1, 2018 · 9 comments
Closed

【结构体中调用XTOSTRUCT失败】 #2

jigetage opened this issue Nov 1, 2018 · 9 comments

Comments

@jigetage
Copy link

jigetage commented Nov 1, 2018

你好:
我在声明的结构体中调用了XTOSTRUCT,但是报错了。提示宏定义TOX_ 和 X_STRUCT_L1是未声明的标识符。代码跟进去文件x2struct.hpp,果然没有找到这两个宏定义。宏定义TOS_也没有找到。
这是怎么回事啊?

@xyz347
Copy link
Owner

xyz347 commented Nov 1, 2018

能简单贴一下结构体定义的代码吗?

@jigetage
Copy link
Author

jigetage commented Nov 1, 2018

嗯嗯

struct StuCommonReturnedInfo { std::string cmdOld; std::string status; std::string result; XTOSTRUCT(M(cmdOld, status, result)); }

@jigetage
Copy link
Author

jigetage commented Nov 1, 2018

struct StuCommonReturnedInfo
{
std::string cmdOld;
std::string status;
std::string result;
XTOSTRUCT(M(cmdOld, status, result));
}

@jigetage
Copy link
Author

jigetage commented Nov 1, 2018

代码跟进去显示的是 X_STRUCT_WRAP_L1, TOX_, TOS_, TOG_ 这四个宏定义找不到哎

@xyz347
Copy link
Owner

xyz347 commented Nov 1, 2018

那有点奇怪了,我这是能运行的:
// main.cpp

#include <iostream>
  
#include <x2struct.hpp>

using namespace std;

struct StuCommonReturnedInfo
{
    std::string cmdOld;
    std::string status;
    std::string result;
    XTOSTRUCT(M(cmdOld, status, result));
};

int main(int argc, char *argv[]) {
    StuCommonReturnedInfo info;
    info.cmdOld = "hello";
    info.status = "good";
    info.result = "nice";
    cout<<x2struct::X::tojson(info)<<endl;
    return 0;
}

运行的结果是:

{"cmdOld":"hello","status":"good","result":"nice"}

g++的版本是:
gcc (Ubuntu 4.9.4-2ubuntu1~12.04) 4.9.4

@xyz347
Copy link
Owner

xyz347 commented Nov 1, 2018

你是不是用的VC?这个没在VC上验证过,你可以加QQ群878041110,我看看怎么改

@jigetage
Copy link
Author

jigetage commented Nov 1, 2018

对的,用的是vc,我加一下哈~谢谢

@jigetage
Copy link
Author

jigetage commented Nov 1, 2018

加了哈

@xyz347
Copy link
Owner

xyz347 commented Nov 2, 2018

已支持VS

@xyz347 xyz347 closed this as completed Nov 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants