K******g 发帖数: 1870 | 1 今天面试被问到template class怎么处理Inheritance问题,我没有答上来,觉得
template class处理inheritance应该与普通的class没有什么区别。
放下电话后,在effective C++的item43里找到了,derived class cannot inherit
public functions from the base class, we need use this->, or using to use
public functions from the base class in the derived class.
但是,我写了个程序, derived class still can inherit public functions from
the base class.(用的是g++编译器)
请问C++的大牛们,到底哪个对啊?难道这种东西是compiler dependent的?
还有这个面试题应该怎么回答呢?多谢了 |
|
g*****h 发帖数: 15 | 2 Inheritance: The Inheritance Cycle, Book 4 (Audiobook) By Christopher
Paolini, read by Gerard Doyle
Publisher: Liste..ning Lib..rary; Unabridged edition 2011 | 31 hours and 17
mins | ISBN: 0739372483 | MP3 | 760 MB
Not so very long ago, Eragon - Shadeslayer, Dragon Rider - was nothing more
than a poor farm boy, and his dragon, Saphira, only a blue stone in the
forest. Now the fate of an entire civilization rests on their shoulders.
Long months of training and battle have brought victories and ho... 阅读全帖 |
|
O*****l 发帖数: 13 | 3 请教这里的C++ guru们,谁能解释一下以下几种C++继承中的基类和继承类在内存中是什
么样的结构:
class A
{
int fieldA;
int func();
}
class B : class A
{
int fieldB;
int func();
}
1. inheritance without virtual functions
[This I know] the memory layout is as simple as: [fieldA fieldB]
2. inheritance with virtual functions
[Not quite clear] looks like in debugger memory [vtprA fieldA fieldB]
should there be a vtable pointer for B?
3. multiple inheritance if there is a class C:A and a class D:B, C
4. multiple inheritance with virtual |
|
l****z 发帖数: 29846 | 4 Biden Blames High Unemployment on ‘This God-Awful Recession We’ve
Inherited’
By Terence P. Jeffrey
March 29, 2012
(CNSNews.com) - At a campaign event in Iowa on Wednesday, Vice President Joe
Biden blamed the continuing high level of unemployment in the United States
on what he called “this God-awful recession we’ve inherited.”
According to the non-partisan National Bureau of Economic Research, the last
recession began in December 2007 and ended in June 2009—just five months
into President Barack... 阅读全帖 |
|
c**a 发帖数: 316 | 5 想不通这个问题, 请指教一下。
如果要访问protected data当然 只能用 private inheritance 不能composition
这个好理解。
但是书上还这么说
if derived class wanna redefine virtual function,
we should we private inheritance.
我觉得不是啊.要redefine virtual function, 咋用都可以。
class Base
{
public:
virtual void f(){std::cout << "Base"; };
};
class DerivedPrivate:private Base
{
public:
virtual void f(){std::cout << "Derived via inheritance"; Base::f();};
};
class DerivedComposite
{
public:
virtual void f(){std::cout << "composite"; b.f();};
private:
Base b |
|
g*********s 发帖数: 1782 | 6 i figure out the following formula to determine the access level
transition. can daniu confirm its correctness?
enum ACC_LEV {
PRIVATE,
PROTECTED,
PUBLIC
};
derived.dat.access_level = min(base.data.access_level,
inheritance.access_level);
so if B::dat is private, and base class B is public inherited by derived
class D, then B::dat in D is still private, and thus inaccessible by D
and its descents.
however, if dat is public while B is private inherited by D, then B::dat
is now private... 阅读全帖 |
|
a****o 发帖数: 686 | 7 这玩意有什么可讨论的?不就是子类所含有的成员授予外界访问的权限的最少限制的归一化么?C++是要用class把struct彻底抛弃掉.设置成private的默认也是出于encapsulation的语言设计理念,这是偶的一孔之见.
private inheritance 类似于 composition. 虽然的哦失去了 is-a 的类型, 但是不同是, private inheritance 允许自身的成员将子类指针转变为基类指针, composition则不可以,而且 private inheritance允许访问基类的 protected. 私有继承可以重载虚函数,但是不能有多个基类的实体.如果有多个,用composition.能用组合就组合,不行了再上private.
我觉得版上大牛们都是不需要查书就能知道的. |
|
|
q***0 发帖数: 43 | 9 One famous example is car inheriting privately from Engine. But even in this
case, composition works and there's no reason why private inheritance is
needed. |
|
e******r 发帖数: 220 | 10 class FooTooBar:virtual FooToo, virtual Bar{
public:
FooTooBar(){std::cout<<"FooTooBar";}
};
只听说过public, protected, private的inheritance, 还有virtual的
inheritance吗?
谢谢 |
|
h**o 发帖数: 548 | 11 What are some of the problems with multiple inheritance? When is it OK to
use multiple inheritance?
除了diamond 还有什么问题?
何时可以用它? 我觉得是当不diamond时就可以用. |
|
t****u 发帖数: 8614 | 12 基本原则是能用composition就用composition,除非composition不能work只能使用
private inheritance才用inheritance。 |
|
g*********s 发帖数: 1782 | 13 统计一下,有多少人不查书就知道准确含义?有多少人平时用这两种继承?
另外明明是public inheritance最常见,为何要把default设成private inheritance? |
|
g*********s 发帖数: 1782 | 14 Just did a quick test. So what's the diff b/w private inheritance and
protected inheritance here?
#include
using namespace std;
class B {
public:
void f() { cout << "B::f()\n"; }
virtual void g() { cout << "B::g()\n"; }
int B_public;
protected:
int B_protected;
private:
int B_private;
};
class D_pub: public B {
public:
void f() { cout << "D_pub::f()\n"; }
virtual void g() { cout << "D_pub::g()\n"; }
void h() { cout << B_protected << endl; }
//void j... 阅读全帖 |
|
c**********e 发帖数: 2007 | 15 【 以下文字转载自 JobHunting 讨论区 】
发信人: careerchange (Stupid), 信区: JobHunting
标 题: C++ Q96: function inheritance
发信站: BBS 未名空间站 (Sun Oct 16 11:50:54 2011, 美东)
Error information in the following code is Error: equals is not a member of
B.
My question: Why equals() is not a member of B but print() is?
While this seems obvious, what is the general rule that a function will be
inherited?
#include
using namespace std;
class A {
public:
bool equal(A a) { return true; }
void print() { cout ... 阅读全帖 |
|
d******3 发帖数: 70 | 16 Youtube Link:
http://youtu.be/7APovvvftQs
People have different opinion about Multiple Inheritance. Some people like
it, while some people hate it. This video explains the benefits and pitfalls
of multiple inheritance, and demonstrates a safe way of using it. |
|
g********d 发帖数: 4174 | 17 Proponents of gay rights scored a victory in New York on Thursday.
An appeals court ruled that the survivor of a same-sex marriage is entitled
to inheritance as a spouse, even if the couple wed out-of-state.
Gay rights group Lamba Legal said the decision was the first of its kind at
an appellate level in New York.
It's illegal for gay couples to marry in New York, but the state recognizes
same-sex marriages from other states and countries.
A recent poll showed more New Yorkers than ever support ... 阅读全帖 |
|
s********t 发帖数: 237 | 18 The Anglo-Saxon Mission : the Third World War and
the Inheritance of the New World
February 2010
Project Camelot | The Anglo-Saxon Mission
Historians tell us that the "Anglo-Saxon Mission" refers to the spread of
Christianity in the 8th century. But over a thousand years later, there is
now another, far more sinister meaning to the phrase.
We recently received 11 pages of information from an insider who was
physically present at a meeting of Senior Masons in the City of London in
2005. What was |
|
P*******e 发帖数: 65 | 19 If the function inherited from the base template class has paramters as the
type of the base template class, the "this->" can be avoided. Otherwise, "
this->" is necessary to tell the compiler the type used in the base template.
template
class BaseClass {
public:
BaseClass() {};
~BaseClass() {};
void Write(T var);
T Read(void);
private:
T variable;
};
template
class ChildClass : public BaseClass {
public:
ChildClass() {};
~ChildClass() {};
void WriteA |
|
c**********e 发帖数: 2007 | 20 Error information in the following code is Error: equals is not a member of
B.
My question: Why equals() is not a member of B but print() is?
While this seems obvious, what is the general rule that a function will be
inherited?
#include
using namespace std;
class A {
public:
bool equal(A a) { return true; }
void print() { cout << "print\n"; }
};
class B: public A {};
int main() {
B b;
bool x = b.equals(b);
b.print();
return 0;
} |
|
S**I 发帖数: 15689 | 21 because "equal" is inherited, but "equals" is not.
of |
|
q****x 发帖数: 7404 | 22 C++这个语言实在有点邪恶。谁能举个例子,非得用private inheritance不可? |
|
x****r 发帖数: 158 | 23 Hey, just wonder if I died of accident, would my parents inherit my
belongings, like car, savings, etc, even if I didn't have a will in place?
I'm single.
Also I have my life insurance through my company with my mom as the
beneficiary. Does she need to actively go claim the benefit or someone will
contact her?
Thanks in advance! |
|
s****a 发帖数: 9912 | 24 找个信的过的熟人给你家打电话通知你的死亡消息
,这不叫INHERITANCE,这叫BENEFICIARY,受益人,
搞个葬礼要几万块了,你的财产卖了也不值那么多吧,
通常是谁给你办葬礼把钱给谁,INSURANCE额外的再
给父母 |
|
L**Y 发帖数: 2145 | 25 Inherited Ira 选择lump sum不用交10%penalty吧。但是算作收入?tax和其他的收入
一样? |
|
m*****a 发帖数: 2609 | 26 【 以下文字转载自 Money 讨论区 】
发信人: memajia (富贵闲人), 信区: Money
标 题: Bad, no more inherit Elite Status for UA award ticket travelers
发信站: BBS 未名空间站 (Tue Dec 16 02:07:10 2014, 美东)
过去用miles出票,出票人的mileageplus number会override traveler's mileageplus
number(看看票就知道了),这样的结果就是traveler享受出票人的mileageplus
account的privileage。如果出票人是elite,traveler也就享受同等待遇。这个功能很
有用,比如你是Gold member,然后用自己的点数给父母出票(你自己不在travler中)
,你的父母也可以享受比如免费托运行李,
但是最近UA变了policy http://www.united.com/CMS/en-US/travel/Pages/BaggageChecked.aspx,注意看note 2):
“... 阅读全帖 |
|
k****i 发帖数: 1072 | 27 My server control inherits from HtmlInputFile,but why the style property is
not showing in the property windows?If you put a HtmlInputFile control on the
form,there is a style property there,so I believe that at the base class
browsable=true. |
|
m******t 发帖数: 2416 | 28
instance
That's a bummer to me. I don't quite understand why it was designed that way,
though. It would seem more intuitive to me that if I manage to get the Method
object from Class C, and specifically call its invoke() on an object, chances
are I would like exactly that method to be executed instead of following the
inheritance graph. |
|
m******t 发帖数: 2416 | 29
OK, let me just remind you guys once again, that Method object is obtained
from a specific Class object. If it only holds the metadata for the method
interface regardless inheritence, the Method objects I got from class A, B,
and C should logically equal to each other, which is evidently not true. |
|
r*****r 发帖数: 397 | 30 I have a strange compiling error, does anybody have this problem before?
There is a base class and an inherit class, very simple,
class BaseClass
{
...
}
class InheritedClass : public BaseClass
{...
}
when i compile,got the error
InheritedClass.h:11: error: expected class-name before ‘{’ token |
|
e******r 发帖数: 220 | 31
那要不要在FooToo 和Bar定义的时候也加上virtual, 换句话说, 下面的是不是
每个inherutance都要加上virtual? 我试了一下, 好象virtual inheritance的个数决定下面的例子的结果.
#include
class Foo
{
public:
Foo(){std::cout<<"Foo";}
};
class Bar: Foo
{
public:
Bar(){std::cout<<"Bar";}
};
class FooToo:virtual Foo
{
public:
FooToo(){std::cout<<"FooToo";}
};
class FooTooBar:virtual FooToo, virtual Bar{
public:
FooTooBar(){std::cout<<"FooTooBar";}
};
int main()
{
FooTooBar a;
return 0;
} |
|
w*****n 发帖数: 9 | 32 不对。
under public inheritance, the original properties will not be changed.
public members will still be public;
protected members will still be protected;
private members will still be private.
如果用public的话,base class的所有public 和 protected member都被继承为
derived class的public member。 但是base的private member没法继承。。
这个理解对不?? |
|
l***t 发帖数: 81 | 33 never use multiple inheritance. |
|
t****t 发帖数: 6806 | 34 这个,也太绝对了吧.没有interface,只好用multiple inheritance来模拟一下,还是可
以用的. |
|
i**p 发帖数: 902 | 35 They are accessible in the 1st inheritence, but not in 2nd (see error in the
following code). What reason made C++ designed this way?
class Base
{
protected:
int pro_stat;
public:
int pub_stat;
};
class Default_Der1 : Base
{
int Der1GetProStat() { return pro_stat; } <- Ok
int Der1GetPubStat() { return pub_stat; } <- Ok
};
class Default_Der2 : Default_Der1
{
int Der2GetProStat() { return pro_stat; } <- Error
int Der2GetPubStat() { return pub_stat; } <- Error
}; |
|
b********n 发帖数: 609 | 36 因为你private inherite了Base,那么Base的东西对Der1来说是可以access的,但对De
r2来说他们就是Der1的private的东东。
the |
|
i**p 发帖数: 902 | 37 It seems what you said is logically. However in Java, the compiler won’t
let you decrease the access of a member during inheritance.
De |
|
l********g 发帖数: 134 | 38 I guess the point of private inheritance is, in your case, class
DerivedPrivate can override virtual functions of class base, while class
DerivedComposite can not. |
|
S*********g 发帖数: 5298 | 39 effective C++的item 42:
Use private inheritance judiciously |
|
c**a 发帖数: 316 | 40 。。。
因为是 private inheritance 了, 所以 Derived 不能act as base
所以和dynamic binding 没什么关系。
then forget it. |
|
b***y 发帖数: 2799 | 41 ☆─────────────────────────────────────☆
gebitan (job, job) 于 (Thu Sep 1 15:09:50 2005) 提到:
class Base{};
class Derived: protected Base {};
Base* bp = new Derived;
when complied, it shows "can't use derived* to initiliaze base*", but if I use
public inheritance, everything is fine.
☆─────────────────────────────────────☆
cdr (可读可写) 于 (Thu Sep 1 15:38:09 2005) 提到:
"Consider a class D derived from a base clas B, ....
If B is a protected base,....
Only friends and members of D and frien |
|
c**********e 发帖数: 2007 | 42 class A
{
public: int x;
protected: int y;
private: int z;
};
class B: private A
{
B(int x_, int y_, int z_) {
x=x_; y=y_; z=z_;
};
Question (Selection)
a. The constructor cannot initialize any of the variables inherited from "A"
because they have all been made private.
b. The constructor cannot initialize member variable "z" because it is
private in A. |
|
j***i 发帖数: 1278 | 43 A, private inheritance 所有的member都是private |
|
d****p 发帖数: 685 | 44 private inheritance means the sub-object of base class is a private "member"
in derived class object - the derived class object itself can still access
any non-private members of the sub-object.
B is right. |
|
d*****d 发帖数: 46 | 45 An advantage of private inheritance over composition is that the former can
have base class protected member access. |
|
e****d 发帖数: 895 | 46 Struct's default is public inheritance. |
|
z*****n 发帖数: 447 | 47 前天面vmware的时候,问到 C++ private inheritance 及其用处,我只谈了一下概念
,说这个可以保证不把父类的成员让其他对象调用,只让derived class的对象看到;
但是深入的也不清楚了,哪些可以解释一下?
多谢 |
|
发帖数: 1 | 48 3 月11日 富豪们,为了你们的生命和财富,捐款吧!
刚才看网上说,歼20入主中国空军,错,大错特错! 歼20不是入主中国空军,歼20是
入主世界空军! 我说过,这是一场世纪之战,但不应该是国家与国家,种族与种族之
间的战争,而是信仰,不同路线之争。
大家都知道这个Hurun 财富榜,其实这是个掠夺财富,权利的集团。而且如果我没有猜
错的话,不管其原始创立人是谁,现在这个集团已经完全被日本人所操控。刚刚发布的
女性亿万富翁榜,就是他们最新的目标,打击对象。这个网单独把中国,印度富豪列举
出来,说明对中国,印度富豪的打击屠杀最有针对性。 而其实,所有这个富豪榜上的
人都具有潜在危险,只不过时间早晚的问题。因为我的出现,而我又是女的,日本人就
仇恨其所有富豪女性,尤其是中国女性成为首要掠夺对象。如果我没有猜错的话,老干
妈很可能已经落入这个集团之手。最新针对的是排名最高的陈丽华,象Panda Express
,我在想,很可能已经落入他们集团之手。当然,所有在这个名单上的人都有危险,不
在这个名单,在其他名单上也有危险。
前天我打印了一些资料,然后夜里他们潜入我的房间偷走了一部分,或者说... 阅读全帖 |
|
n********n 发帖数: 8336 | 49 对imputed sin的定义有争议,见下一种观点
----------------------
Question: "What is the definition of sin?"
Answer: Sin is described in the Bible as transgression of the law of God (1
John 3:4) and rebellion against God (Deuteronomy 9:7; Joshua 1:18). Sin had
its beginning with Lucifer, probably the most beautiful and powerful of the
angels. Not content with his position, he desired to be higher than God, and
that was his downfall, the beginning of sin (Isaiah 14:12-15). Renamed
Satan, he brought sin to the hum... 阅读全帖 |
|