c++ inheritance syntax

Possible Duplicate: What are access specifiers? Should I inherit with private, protected or public? Difference between private, public and protected inheritance in C++ To all you cpp experts, In c++ inheritance, class B : public A { }; I am just curious why is the keyword public needed here? Does it mean something? It means public members in A are inherited by B and are also public fr

c ++继承语法

可能重复: 什么是访问说明符? 我应该继续与私人,受保护或公共? C ++中私有,公共和受保护继承之间的区别 对你所有的cpp专家来说,在c ++继承中, class B : public A { }; 我只是好奇为什么这里需要关键字public? 这是否意味着什么? 这意味着A中的public成员由B继承,并且也是B公开的。 替代方案是: 保护 - A公共成员在B受到保护,其他人保持不变。 私人 - A所有成员在B都是私有的。 规则不适用于隐

What is difference between protected and private derivation in c++

Possible Duplicate: Difference between private, public and protected inheritance in C++ What is difference between deriving as protected or private in c++? i am not able to figure out, since both seem to restrict base class member access from derived class object Let's consider a code example showing what would be allowed (or not) using different levels of inheritance: class BaseClas

c ++中的protected和private派生之间有什么区别?

可能重复: C ++中私有,公共和受保护继承之间的区别 在c ++中派生为受保护或私有的有什么区别? 我无法弄清楚,因为两者似乎都限制了派生类对象的基类成员访问 让我们考虑一个代码示例,展示使用不同级别的继承将允许(或不允许)的内容: class BaseClass {}; void freeStandingFunction(BaseClass* b); class DerivedProtected : protected BaseClass { DerivedProtected() { freeStandingFu

Is partial class template specialization the answer to this design problem?

Say you have a class who's job it is to connect to a remote server. I want to abstract this class to provide two versions, one that connects through UDP and the other through TCP. I want to build the leanest runtime code possible and instead of using polymorphism I am considering templates. Here is what I'm envisioning but I'm not sure it's the best way of doing this: class ud

部分类模板专业化是这个设计问题的答案吗?

假设你有一个班级负责连接远程服务器。 我想抽象这个类来提供两个版本,一个通过UDP连接,另一个通过TCP连接。 我想构建可能的最简化运行时代码,而不是使用多态我正在考虑模板。 这是我的设想,但我不确定这是做这件事的最佳方式: class udp {}; class tcp {}; template<class T,typename X> class service { private: // Make this private so this non specialized version can't be used service(); }; tem

Difference in implementation of malloc and new. Stack implementation?

While allocating memory, the new operator throws an exception if the memory is not available. On the other hand, malloc returns a NULL. What is the reason for the difference in implementation. Also, on static memory allocation, ie on the stack, is there an exception if we run out of memory? I have already gone through the link What is the difference between new/delete and malloc/free? but d

malloc和new的实现差异。 堆栈实现?

在分配内存时,如果内存不可用,新运算符会引发异常。 另一方面,malloc返回一个NULL。 执行差异的原因是什么? 另外,在静态内存分配上,即在堆栈上,如果内存不足,是否会有异常? 我已经通过链接new / delete和malloc / free有什么区别? 但没有得到我对这两者实施差异的回答 C代码的问题在于你应该检查函数的返回值以确保它们正常工作。 但是写了很多代码,没有检查返回值,结果在最不出意料的时候爆炸得非常好。

What is difference between instantiating an object using new vs. without

In C++, Aside from dynamic memory allocation, is there a functional difference between the following two lines of code: Time t (12, 0, 0); //t is a Time object Time* t = new Time(12, 0, 0);//t is a pointer to a dynamically allocated Time object I am assuming of course that a Time(int, int, int) ctor has been defined. I also realize that in the second case t will need to be deleted as it was

使用new和without实例化对象有什么区别

在C ++中, 除了动态内存分配,以下两行代码之间还有一个功能差异: Time t (12, 0, 0); //t is a Time object Time* t = new Time(12, 0, 0);//t is a pointer to a dynamically allocated Time object 我假设当然已经定义了一个Time(int,int,int)ctor。 我也意识到,在第二种情况下,由于它是在堆上分配的,因此需要删除它。 还有其他的区别吗? 该行: Time t (12, 0, 0); ...在局部范围内分配一个类型为Time

what is the difference between Malloc and new operator to allocate a memory?

Possible Duplicate: What is the difference between new/delete and malloc/free? I was confused when I create an object by using new operator in C++. There must be difference between malloc and new operator that would allow me to resize the memory block. If I want to allocate a memory I use malloc but what if I use a new operator? İsn't it allocate a memory? Can you explain that when s

Malloc和新运营商分配内存有什么区别?

可能重复: new / delete和malloc / free有什么区别? 我在C ++中使用new运算符创建对象时感到困惑。 malloc和new运算符之间必须有区别,这将允许我调整内存块的大小。 如果我想分配一个内存我使用malloc但如果我使用一个新的操作符? 它不分配内存? 你能解释一下,当我使用malloc,什么时候应该使用新的? X* ptr = new(1,2) X; obj = (ObjID *)malloc( sizeof(ObjID) ); 非常感谢。 在C ++中,您应该始终使用ne

malloc/free and new/delete compatibility in C++?

There is a nice comparison of malloc/free and new/delete here, and good explanations how malloc() and free() work here. Obviously, we shall not mix them - use free with new or delete with malloc. We can see a lot of open source projects, with many contributors, using both of these mechanisms, while respecting the above "no-mix" rule. Usualy, you have only one way in one file (one au

malloc / free和new / delete在C ++中的兼容性?

这里有一个比较好的malloc / free和new / delete,以及malloc()和free()如何在这里工作的很好的解释。 显然,我们不能混用它们 - 使用new或free来使用malloc。 我们可以看到许多开源项目,与许多贡献者一起使用这两种机制,同时尊重上述“不混合”规则。 Usualy,你在一个文件中只有一种方法(一个作者,一个偏好)。 我已经分叉了这样一个项目,并且使用新的/删除来添加一些功能。 但是我遇到了一些好奇的记忆腐败。

What is the difference between "new" and "malloc" and "calloc" in C++?

What is the difference between "new" and "malloc" and "calloc" and others in family? (When) Do I need anything other than "new" ? Is one of them implemented using any other? new and delete are C++ specific features. They didn't exist in C. malloc is the old school C way to do things. Most of the time, you won't need to use it in C++. mallo

C ++中的“new”和“malloc”和“calloc”有什么区别?

“新”,“malloc”和“calloc”等家族的区别是什么? (什么时候)我需要“新”以外的任何东西吗? 其中之一是否使用其他方法实施? new和delete是C ++特有的功能。 他们在C中不存在malloc是老派C做事的方式。 大多数时候,你不需要在C ++中使用它。 malloc分配未初始化的内存。 分配的内存必须free发布。 calloc就像malloc但用一个常量(0)初始化分配的内存。 它需要free释放。 new通过调用构造函数初始化分配的内存

New, delete, malloc, free

new and delete are said to be preprocessors while malloc and free are functions. What is meant by new and delete being preprocessors? new and delete are C++ operators (like +, (), etc.) whereas malloc and free are (C) functions. Some operators (including new and delete) can be overloaded.

新建,删除,malloc,免费

据说new和delete是预处理器,而malloc和free是函数。 new和delete是指预处理器是什么意思? new和delete是C ++ 运算符 (如+,()等),而malloc和free是(C)函数。 某些运算符(包括new和delete)可能会超载。

A bit confused on exact meaning of dynamic memory allocation for C++

I've heard conflicting things concerning the exact meaning of dynamic, and for that matter automatic, memory allocation. I've heard the stack be referred to as both automatic memory allocation and as dynamic memory allocation. I can see both as the stack memory block size is determined before program execution and so it's maximum size cannot grow during runtime. However, during pro

对C ++动态内存分配的确切含义有点困惑

我听说过有关动态确切含义的矛盾事件,以及关于自动内存分配的问题。 我听说这个堆栈被称为自动内存分配和动态内存分配。 我可以看到,因为堆栈内存块大小是在程序执行前确定的,所以它的最大大小在运行时不能增长。 但是,在程序执行过程中,随着函数数据被推入并弹出堆栈,堆栈不断增长和收缩。 那么从这个意义上讲,这不是动态的内存分配? 如果是这样的话,只是将堆称为动态的,这不是令人困惑吗? 有人可以帮我澄