#include <iostream>
#define CONCATENATE t; Box(); t
#define END ;
using namespace std;
class Box
{
public:
Box(){ }
Box(string _txt){ }
Box operator|(const Box& b)
{
cout<<"hi from op |"<<endl;
Box box;
return box;
}
void operator+()
{
}
public:
string str;
};
int main()
{
Box t;
Box tt;
CONCATENATE //this works
CONCATENATE CONCATENATE //this doesn't work because cant understand tt object
END
}
如果我給CONCATENATE CONCATENATE編譯器說分號缺少多數正確但編譯器應該理解t;框(); TT;框();因爲在分析階段刪除空格。好奇的類對象連接C++
如果我編寫CONCATENATE END編譯器執行那個並且是正確的 t;框();噸; 如果我編寫CONCATENATE CONCATENATE END編譯器執行那個並且不正確 t;框(); t t;框();噸;因爲了解分號丟失,但在這種情況下,我希望編譯器明白應該執行對象tt並忽略空格。
我該怎麼做那些傢伙?
更新
預處理器連接了字符串到TT;目的?
int main(){ Box t; Box tt; //this work (is such 2 times CONCATENATE macro) t; Box(); tt; Box(); t END //this doesnt work CONCATENATE CONCATENATE END }
你究竟想在這裏實現什麼? [這幾乎肯定是錯誤的做法。](http://meta.stackexchange.com/q/66377/242291) – BoBTFish
檢查我的update.thanks! –
@ jay_gr13你的更新仍不能很好地解釋你對這個構造的用例。對我來說毫無意義。 –