如何在C ++(C代码)中执行此操作 [英] How to do this in C++ (C code)
问题描述
在C中,我有这个:
#define doStuff(var)func(var ## _ 1,var ## _ 2)
void func(int v,int v2)
{
printf("%d,%d \ n",v,v2);
}
int main()
{
int myvar_1 = 1;
int myvar_2 = 2;
doStuff(myvar);
// ...
}
我想做一个类来封装func,但是我怎么能和一个类做同样的事情呢?我想做这样的事情:
int myvar_1 = 1;
int myvar_2 = 2;
CMyClass c;
c.doStuff(myvar);
我该怎么做?
感谢您的帮助,
S.
ti ********* @ gmail.com 写道:
in C ,我有这个:
#define doStuff(var)func(var ## _ 1,var ## _ 2)
void func( int v,int v2)
{
printf("%d,%d \ n",v,v2);
}
int main()
{
int myvar_1 = 1;
int myvar_2 = 2;
doStuff(myvar);
// ...
}
我想要做一个类来封装func,但我怎么能和一个类做同样的事情呢?我想做这样的事情:
int myvar_1 = 1;
int myvar_2 = 2;
CMyClass c;
c.doStuff(myvar);
我该怎么做?
我不会。这是一个维护噩梦。
但如果你愿意,你可以用完全相同的方式完成相同的
宏。 c.doStuff(myvar)行扩展为c.func(myvar_1,myvar_2)
有什么问题?
27fév,18:51,red floyd< no.s ... @ here.dudewrote:
timor.su ... @ gmail .com写道:
C中的
,我有:
#define doStuff (var)func(var ## _ 1,var ## _ 2)
void func(int v,int v2)
{
printf("%d,%d \ n",v,v2);
}
int main()
{
int myvar_1 = 1;
int myvar_2 = 2;
doStuff(myvar);
// ...
}
我想做一个类来封装func,但我怎么能这样做
一样有课的东西?我想做这样的事情:
int myvar_1 = 1;
int myvar_2 = 2;
CMyClass c;
c.doStuff(myvar);
我该怎么做?
我不会。这是一个维护噩梦。
但是如果你愿意的话,你可以用完全相同的方式使用完全相同的
宏。行c.doStuff(myvar)扩展为c.func(myvar_1,myvar_2)
有什么问题?
问题是我不知道该把什么作为参数...
#define doStuff( var)func(var ## _ 1,var ## _ 2)
void func(int v,int v2)
{
printf( %d,%d \ n,v,v2);
}
class MyClass
{
public:
MyClass();
void DoTheStuff(????)//< - 我该放什么?
{
doStuff(theVar);
}
};
int _tmain(int argc,_TCHAR * argv [])
{
int myvar_1 = 1;
int myvar_2 = 2;
MyClass c;
c.DoTheStuff(myvar);
返回0;
}
我有什么可以取代???
我想有一个合适的解决方案,但你应该知道我
可以''修改宏,我无法访问功能代码
功能(这是一个示例测试)
谢谢你你的帮助
最好,
S.
< a href =mailto:ti ********* @ gmail.com> ti ********* @ gmail.com 写道:
27fév,18:51,red floyd< no.s ... @ here.dudewrote:
> timor .su ... @ gmail.com写道:
>>在C中,我有:
>> #define doStuff(var)func(var ## _ 1,var ## _ 2)
>> void func(int v,int v2)
{/> printf("%d,%d \ n",v,v2);
}
>> int main()
{myvar_1 = 1;
int myvar_2 = 2;
doStuff(myvar);
// ...
}
>>我想上课封装吃了这个功能,但我怎么能和班级做同样的事呢?我想做这样的事情:
>> int myvar_1 = 1;
int myvar_2 = 2;
CMyClass c;
c.doStuff(myvar);
>>我该怎么做?
我不会。这是一个维护噩梦。
但是如果你愿意,你可以用完全相同的方式完成相同的宏。 c.doStuff(myvar)行扩展为c.func(myvar_1,
myvar_2)
有什么问题?
问题是我不知道该把什么作为参数...
#define doStuff(var)func(var ## _ 1,var ## _ 2)
void func(int v,int v2)
{
printf("%d,%d \ n",v,v2);
}
class MyClass
{
public:
MyClass();
void DoTheStuff(????)//< - 我该怎么办?放在这里?
{
doStuff(theVar);
}
没有。只需在这里实现''func'':
void func(int v,int v2){:: func(v,v2); }
};
int _tmain(int argc,_TCHAR * argv [])
{
int myvar_1 = 1;
int myvar_2 = 2;
MyClass c;
c.DoTheStuff (MYVAR);
不,这应该是
c.doStuff(myvar);
返回0;
}
我有什么可以取代???
我想有一个合适的解决方案,但你应该知道我不能修改宏,而且我无法访问功能代码
函数(这是一个示例测试)
没有正确的解。这是一个不好意思(tm)无论你怎么用b / b
切片它。
V
-
请在通过电子邮件回复时删除资金''A'
我没有回复最热门的回复,请不要问
in C, I have this :
#define doStuff(var) func(var##_1, var##_2)
void func(int v, int v2)
{
printf("%d, %d\n", v, v2);
}
int main()
{
int myvar_1 = 1;
int myvar_2 = 2;
doStuff(myvar);
// ...
}
I want to do a class to encapsulate the func, but how can I do the
same thing with a class ? I would like to do something like this :
int myvar_1 = 1;
int myvar_2 = 2;
CMyClass c;
c.doStuff(myvar);
How can I do that ?
Thanks for your help,
S.
ti*********@gmail.com wrote:in C, I have this :
#define doStuff(var) func(var##_1, var##_2)
void func(int v, int v2)
{
printf("%d, %d\n", v, v2);
}
int main()
{
int myvar_1 = 1;
int myvar_2 = 2;
doStuff(myvar);
// ...
}
I want to do a class to encapsulate the func, but how can I do the
same thing with a class ? I would like to do something like this :
int myvar_1 = 1;
int myvar_2 = 2;
CMyClass c;
c.doStuff(myvar);
How can I do that ?I wouldn''t. It''s a maintenance nightmare.
But if you want to, you do it the exact same way with the exact same
macro. The line c.doStuff(myvar) expands out to c.func(myvar_1, myvar_2)
What''s the problem?
On 27 fév, 18:51, red floyd <no.s...@here.dudewrote:timor.su...@gmail.com wrote:in C, I have this :
#define doStuff(var) func(var##_1, var##_2)
void func(int v, int v2)
{
printf("%d, %d\n", v, v2);
}
int main()
{
int myvar_1 = 1;
int myvar_2 = 2;
doStuff(myvar);
// ...
}
I want to do a class to encapsulate the func, but how can I do the
same thing with a class ? I would like to do something like this :
int myvar_1 = 1;
int myvar_2 = 2;
CMyClass c;
c.doStuff(myvar);
How can I do that ?
I wouldn''t. It''s a maintenance nightmare.
But if you want to, you do it the exact same way with the exact same
macro. The line c.doStuff(myvar) expands out to c.func(myvar_1, myvar_2)
What''s the problem?
the problem is that I don''t know what to put as parameters ...
#define doStuff(var) func(var##_1, var##_2)
void func(int v, int v2)
{
printf("%d, %d\n", v, v2);
}
class MyClass
{
public:
MyClass();
void DoTheStuff(????) // <-- what should I put here ?
{
doStuff(theVar);
}
};
int _tmain(int argc, _TCHAR* argv[])
{
int myvar_1 = 1;
int myvar_2 = 2;
MyClass c;
c.DoTheStuff(myvar);
return 0;
}
with what can i replace the ???
I would like to have a proper solution, but you should know that I
can''t modify the macro and I don''t have access to the func code
function (this is an example test)
Thanks for your help
best,
S.
ti*********@gmail.com wrote:On 27 fév, 18:51, red floyd <no.s...@here.dudewrote:>timor.su...@gmail.com wrote:>>in C, I have this :
>>#define doStuff(var) func(var##_1, var##_2)
>>void func(int v, int v2)
{
printf("%d, %d\n", v, v2);
}
>>int main()
{
int myvar_1 = 1;
int myvar_2 = 2;
doStuff(myvar);
// ...
}
>>I want to do a class to encapsulate the func, but how can I do the
same thing with a class ? I would like to do something like this :
>>int myvar_1 = 1;
int myvar_2 = 2;
CMyClass c;
c.doStuff(myvar);
>>How can I do that ?
I wouldn''t. It''s a maintenance nightmare.
But if you want to, you do it the exact same way with the exact same
macro. The line c.doStuff(myvar) expands out to c.func(myvar_1,
myvar_2)
What''s the problem?
the problem is that I don''t know what to put as parameters ...
#define doStuff(var) func(var##_1, var##_2)
void func(int v, int v2)
{
printf("%d, %d\n", v, v2);
}
class MyClass
{
public:
MyClass();
void DoTheStuff(????) // <-- what should I put here ?
{
doStuff(theVar);
}Nothing. Just implement the ''func'' here:
void func(int v, int v2) { ::func(v,v2); }
};
int _tmain(int argc, _TCHAR* argv[])
{
int myvar_1 = 1;
int myvar_2 = 2;
MyClass c;
c.DoTheStuff(myvar);No, this should be
c.doStuff(myvar);
return 0;
}
with what can i replace the ???
I would like to have a proper solution, but you should know that I
can''t modify the macro and I don''t have access to the func code
function (this is an example test)There is no "proper" solution. It''s a BAD IDEA(tm) no matter how
you slice it.
V
--
Please remove capital ''A''s when replying by e-mail
I do not respond to top-posted replies, please don''t ask
这篇关于如何在C ++(C代码)中执行此操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!