English 中文(简体)
在C++中,是否有实际办法将一项职能限于某种职能?
原标题:In C++, is there a practical way to restrict the calling of one function to certain function?
  • 时间:2011-10-30 16:20:42
  •  标签:
  • c++

C++不支持加固的职能。 Saye 我有自己的职能和职能,我希望保证,只有有人能够说的,没有人能够这样做?

最佳回答

无,但你可以永远建立职能级别。 例如:

void MyFunction() {

    class InnerClass {
    public:
        static void InnerFunction() {
        }
    };

    InnerClass::InnerFunction();
    InnerClass::InnerFunction();
    // ...

};
问题回答

这样做有多种方式(无100%的防弹,有人总是可以ed取你的来源档案),但只有一种方式。

  1. 规定班级内的职能,使之为私人职能,并履行你想要称为“朋友”的职能。

  2. 假设您希望通过<条码><><>/代码>可调用,但除别的外,另一种方式是将<条码>a<>>> 和<条码> 和<条码> 放在自己的源文档中,并使<条码>a<>>><>>>>>>>> static。 这样,<代码>a只能向同一来源档案中的实体看见,但<代码>b<>>>/代码”对签字的所有人来说是显而易见的。

Or 3. If you can use lambdas (i.e. your compiler supports this feature of C++11):

void a() {
    auto f = []() { /* do stuff */ }

    f();
}
int main()
{
    class a
    {
        public:
            static void foo(){}
    };
    a::foo();
}

它为我编纂了罚款,因此,在C++中,你可以拥有“冻结职能”。





相关问题
Undefined reference

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 ...

C++ Equivalent of Tidy

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 ...

Template Classes in C++ ... a required skill set?

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?

Print possible strings created from a Number

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->...

typedef ing STL wstring

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, ...

C# Marshal / Pinvoke CBitmap?

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 ...

Window iconification status via Xlib

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?

热门标签