公共标题 [英] public headers

查看:78
本文介绍了公共标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

i想要创建c ++库(供我使用),但我不知道我怎么做b $ b必须做的只有公共标题只包含公众声明。

我在C中用来将* .c中的私有声明和* .h中的公共

声明放在一起。但是如何在c ++中做到这一点。

如果有人可以帮助我,他会很好。

谢谢。

解决方案

ie***@free.fr 写道:


i想要创建c ++库(供我使用),但我不知道我必须如何才能拥有只包含公开声明的标题。

我在C中使用将* .c中的私有声明和* .h中的公共

声明。但是如何用c ++做到这一点。

如果有人可以帮助我,他会很好。



你认为C / C ++在

方面有什么区别?将您的公共声明放在.h文件中,将您的私有

声明和定义放在.cpp中。现在,不要让公共和私人访问说明符的存在让你感到困惑。这些不是你以前在C中所拥有的(据我所知),这些是为了防止错误,而不是真正保护你的知识产权。


V

-

请在通过电子邮件回复时删除资金''A'

我没有回复最热门的回复,请不要问


你认为在


尊重?



很多。


将您的公开声明放在.h文件中,放入您的私人
.cpp中的
声明和定义。



是的,但我的意思是我有一个私人和公共成员的课程,而且我只需要公开显示在标题中而不是私有。


现在,不要让公共和私人访问说明符的存在感到困惑。这些不是你以前在C中所拥有的(据我所知),这些是为了防止错误,而不是真正保护你的知识产权。



我知道,我只是认为如果会员是私人的,那么标题中一定不能是

< blockquote class =post_quotes>
>

V

-

请删除大写''A'的时候通过电子邮件回复

我没有回复最热门的回复,请不要问



< blockquote> 9月25日,9:38 pm,ie ... @ free.fr < ie ... @ free.frwrote:


现在,不要让存在
$ b ''public''和''private''访问说明符$ b混淆了你。这些不是你以前在C中所拥有的(据我所知),这些是为了防止错误,而不是真正保护你的知识产权。



我知道,我只是认为如果一个成员是私人的,那么标题中不得出现



这是不正确的。它必须在标题中,否则编译器将无法正确创建对象,因为它必须创建(new)

任何具有该对象的实例私人物品的空间正确

点。


如果你真的想要隐藏这些细节,你需要实现一个

抽象基类,或类似的东西。


Hello,
i want to create c++ libraries (for my use) but I don''t know how I
must do to have headers which contain only the public declarations.
I used in C to put the private declarations in *.c and the public
declaration in *.h. But how to do that in c++.
If someone could help me, he would be nice.
Thank you.

解决方案

ie***@free.fr wrote:

i want to create c++ libraries (for my use) but I don''t know how I
must do to have headers which contain only the public declarations.
I used in C to put the private declarations in *.c and the public
declaration in *.h. But how to do that in c++.
If someone could help me, he would be nice.

What difference do you think exists between C and C++ in that
respect? Put your public declarations in .h files, put your private
declarations and definitions in .cpp. Now, don''t let the presence
of ''public'' and ''private'' access specifiers confuse you. Those are
not what you used to have in C (as I understand it), those are to
prevent errors, not really to protect your intellectual property.

V
--
Please remove capital ''A''s when replying by e-mail
I do not respond to top-posted replies, please don''t ask


What difference do you think exists between C and C++ in that

respect?

Many.

Put your public declarations in .h files, put your private
declarations and definitions in .cpp.

Yeah but I mean I got a class with private and public members and I
just want the public appear in headers not private.

Now, don''t let the presence
of ''public'' and ''private'' access specifiers confuse you. Those are
not what you used to have in C (as I understand it), those are to
prevent errors, not really to protect your intellectual property.

I know it, I just think that if a member is private it must not be
present in headers.

>
V
--
Please remove capital ''A''s when replying by e-mail
I do not respond to top-posted replies, please don''t ask



On Sep 25, 9:38 pm, "ie...@free.fr" <ie...@free.frwrote:

Now, don''t let the presence
of ''public'' and ''private'' access specifiers confuse you. Those are
not what you used to have in C (as I understand it), those are to
prevent errors, not really to protect your intellectual property.


I know it, I just think that if a member is private it must not be
present in headers.


That''s incorrect. It must be in the header or the compiler will not
be able to create the object correctly, since it has to create ("new")
any instances with the space for the private items in the correct
spots.

If you really want to hide those details, you need to implement an
abstract base class, or something along those lines.


这篇关于公共标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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