我想写一个小的工具,采用C++方案(单一文件),发现“主要”功能,并给它增加2个功能,一个在开始时,一个在最后。
如何做到这一点? 我能否使用g++的教区机制(或任何其他教区)?
我想写一个小的工具,采用C++方案(单一文件),发现“主要”功能,并给它增加2个功能,一个在开始时,一个在最后。
如何做到这一点? 我能否使用g++的教区机制(或任何其他教区)?
正如一些评论家所建议的,请允许我提出我的想法,作为答案:
基本上,这一概念是:
... original .cpp file ...
#include <yourHeader>
namespace {
SpecialClass specialClassInstance;
}
在<条码>特殊目录条码>中,例如:
class SpecialClass {
public:
SpecialClass() {
firstFunction();
}
~SpecialClass() {
secondFunction();
}
}
这样,你就不需要把C++的档案整理起来。 由于你正在宣布全球,其建筑商将在<代码>main之前开张,其承载人将在<代码>main/code>后开张。
The downside is that you don t get to know the relative order of when your global is constructed compared to others. So if you need to guarantee that firstFunction
is called
before any other constructor elsewhere in the entire program, you re out of luck.
如果你想要使其坚固,则使用 图书馆。
我听到海合会教区既难以使用,也更难以在不援引整个工具链的情况下使用。 我将审判部族C/C++教区(和在
Adding a function at the beginning of main()
and at the end of main()
is a bad idea. What if someone calls return
in the middle?.
A better idea is to instantiate a class at the beginning of main()
and let that class destructor do the call function you want called at the end. This would ensure that that function always get called.
如果你控制了你的主要方案,你就可以打上作此工作的文字,而且这远非易事。 简而言之,确保插入点是显而易见的(奇评、需要插入标语、你选择的)和独一无二的(包括禁止一般编码做法,如果你需要的话,以确保你所需要的独特性是真实的)。 然后,一个 d形的 ha形工具可以读到来文方,找到独特的标识,并插入你所希望的电话,就会奏效。
如果主要方案的引力来自其他来源,而且你没有控制,那么你就需要有完整的C++方案改造引擎。 你不希望建立这一环境,因为只有C++区系为争取正确作出巨大努力。 这里的其他发言者提到Clang和海湾合作委员会作为答案。
另一种选择是。 DMS 软件重新设计工具箱,其C++前端。 投管处使用C++前端,可以编造密码(针对C++的各种方言),建立海岸警卫队,执行全名/型决议,确定所有标志的含义/定义/用途。 该系统提供程序和源对源的转变,以便能够对近海进行变革,并可以重新编制汇编的源代码,使之与原来的评论完全一致。
I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...
I have been searching for sample code creating iterator for my own container, but I haven t really found a good example. I know this been asked before (Creating my own Iterators) but didn t see any ...
Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...
I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?
Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...
Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...
I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...
Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?