gpt4 book ai didi

C++ - 为什么在使用宏时此代码不起作用?

转载 作者:太空宇宙 更新时间:2023-11-04 14:52:58 25 4
gpt4 key购买 nike

当我在宏中使用 a->url 时它失败了,但是当我替换 a->url 并手动放入字符串时它可以工作。如何使 a->url 与宏兼容?

g++    -c -g -std=c++11 -MMD -MP -MF "build/Debug/GNU-MacOSX/main.o.d" -o build/Debug/GNU-MacOSX/main.o main.cpp
main.cpp:18:35: error: expected ';' after expression
cout << MANIFEST_URL(a->url);

代码:

#include <iostream>
#include <ctime>
#include <string>
using namespace std;

#define MANIFEST_URL(REPLACE) "https://" REPLACE "/manifest.json";

typedef struct custom {
char *id;
string url;
custom *next;
} custom;

int main() {
custom *a;
a = new custom;
a->url = "www.google.com";
cout << MANIFEST_URL(a->url);
cout << a->url;
return 0;
}

最佳答案

您的宏扩展为:

cout << "https://" a->url "/manifest.json";;

这显然是无效的。

关于C++ - 为什么在使用宏时此代码不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42659580/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com