简单的方法来禁用C ++ code的一部分 [英] Simple ways to disable part of C++ code

查看:76
本文介绍了简单的方法来禁用C ++ code的一部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是不是解决特定问题的典型问题,这是相当脑的运动,但我不知道是否有人有一个解决方案。

This isn't a typical question to solve a specific problem, it's rather a brain exercise, but I wonder if anyone has a solution.

在发展,我们经常需要禁用或切换code的某些部分,检查不同的方法。要做到这一点,我们使用的意见或 #define语句,但我最喜欢的是:

In development we often need to disable or switch some parts of code to check different approaches. To do this we use comments or #defines, but my favorite is:

//*
[code here]
//*/

现在,当您删除只是第一个斜线code将成为注释掉的。

Now when you remove just the first slash the code will become commented-out.

问题:有没有什么办法来实现类似的的if-else code开关?我试图找到它,但我一直有一些问题,但没有找到工作的解决方案。

The question: is there any way to implement similar if-else code switch? I tried to find it but I always had some problem and couldn't find a working solution.

也许你知道任何类似的把戏?

And maybe do you know any similar tricks?

推荐答案

我不知道我应该张贴这一点,因为它不是,我认为是'好code',但我会承认我曾经使用的以下技术作为一种快速正肮脏的方式才能够code两个小片段,当我刚检查出来的东西之间​​快速切换:

I'm not sure I should post this because it's not something I think is 'good code', but I'll admit to having used the following technique as a quick-n-dirty way to be able to quickly switch between two small snippets of code when I'm just checking something out:

// in the following , foo() is active:
/**/ foo(); /*/ bar(); /**/

现在只是删除了星号的一个在前面:

Now just remove one of the asterisks at the front:

// now bar() is active:
/*/ foo(); /*/ bar(); /**/

当然,这不应该让过去的只是检查的事情了的阶段...

Of course, this should never make it past the "just checking things out" phase...

这篇关于简单的方法来禁用C ++ code的一部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆