c*********e 发帖数: 16335 | 1 可以试试把那2 classes(大class以及它的inner class)做成jar文件,在classpath里
加入这个jar文件,就象加library那样,不過我没试过,就是一想法。 |
|
t***a 发帖数: 416 | 2 我就是看了你的帖子,和你程序的结果,自己瞎联想的
constant pool(是叫这个名字么)是per class的,而且是runtime的,但是这个string
的instance肯定是整个jvm来share的,只有一个,那么constant pool里应该只存ref,
而且还是strong ref(它不能让这个instance被gc)
string pool是存soft ref的,它是所有classes共享的,如果所有class里的strong
ref都被回收了,那么string pool里面引用的这个string instance也会被回收的
这么看来。。。的确是不同的。。。。楼主为啥要比较他们两个呢? |
|
t***a 发帖数: 416 | 3 我就是看了你的帖子,和你程序的结果,自己瞎联想的
constant pool(是叫这个名字么)是per class的,而且是runtime的,但是这个string
的instance肯定是整个jvm来share的,只有一个,那么constant pool里应该只存ref,
而且还是strong ref(它不能让这个instance被gc)
string pool是存soft ref的,它是所有classes共享的,如果所有class里的strong
ref都被回收了,那么string pool里面引用的这个string instance也会被回收的
这么看来。。。的确是不同的。。。。楼主为啥要比较他们两个呢? |
|
n******1 发帖数: 3756 | 4 http://docs.oracle.com/javase/specs/jls/se7/html/jls-3.html#d5e
Literal strings within the same class (§8) in the same package (§7)
represent references to the same String object (§4.3.1).
Literal strings within different classes in the same package represent
references to the same String object.
Literal strings within different classes in different packages likewise
represent references to the same String object.
Strings computed by constant expressions (§15.28) are computed at compile
time and... 阅读全帖 |
|
e*****t 发帖数: 1005 | 5 duplicate class: check if you do have duplicate classes (two classes with th
e same name in the same package).
About moving a variable reference, the compiler is right if you are referenc
ing it from any innerclass, it needs to be decalred final. If it can't be fi
nal, then you shouldn't refrence it directly, in other words, you should pas
s it in somehow.
accessed |
|
s*****e 发帖数: 33 | 6 Want to have the following definitions:
class Foo
{
private:
class FooA
{
};
struct FooB
{
int x_;
FooA *p_;
}
}
Do you know how to make the above definition possible, basically, how to make
FooA is accessible from FooB? Thanks a lot. |
|
|
t****t 发帖数: 6806 | 8 hmm, i am not sure on this
template class K> ...
maybe you can not use "typename K" here. but what i meant is, when they can
both be used then they are equivalent [14.1, clause 2] |
|
S******8 发帖数: 24594 | 9 1. Class is defined in the dll and labelled "export".
2. client application is linked to the lib of the dll and can access the dll.
3. The client create an object of that exported class in the heap (by "new
operator").
4. The client then use that object pointer to perform a series of work, with
no problem.
5. In the destructor of the client's class, if I try to delete that object,
I got a Assert failure: InvalidHeapPointer.
Anybody with any suggestion on this problem?
Thanks!!!!! |
|
a*********e 发帖数: 697 | 10 看书时好像没注意,忽然觉得不明白了。
superclass
class A {
array m_arry[];
init(array); //to init m_arry
}
subclass
class B {
sort(this.m_arry);
}
main(){
A a;
B b=(B)a;
b.sort();
}
这样写把super class 对象downcast成subclass 的对象是会有问题的。调用b.sort()
是会出错,还是不出错但sort只是作用在b自己的m_arry上? 如果写:
b.init(a.m_arry);
b.sort();
是否就可以了? |
|
e*****t 发帖数: 1 | 11 Downcast is for Compile-time type check, i.e., for the compilers to do error
checking. For example, if you declare a class A and then point it to a Run-
time type B like the following,
Class A{
A(); //ctor
int a;
}
Class B extends A{
super();
sort();
}
A a = new B();
You can not say
a.sort(); //compile error
But you can say
(B)a.sort(); //compile OK
====
if you say
A a = new A();
B b = a;
you will get a compile error.
=======
if you say
A a = new A();
B b = new B();
a = b; // this is OK.
a.sort |
|
f********a 发帖数: 1109 | 12 【 以下文字转载自 JobHunting 讨论区 】
发信人: fololunsia (我心飞扬), 信区: JobHunting
标 题: 关于C++中一个Class的大小
发信站: BBS 未名空间站 (Sun May 27 13:54:24 2007)
class A{
public:
int x;
void foo() const{
cout<<"A Class"<
}
};
int main(){
cout<
return 0;
}
结果是4 bytes。那么foo()的空间到哪里去了? |
|
q***s 发帖数: 2243 | 13 在做一个程序,需要用到两个class的交叉引用,比如在A类中要用到B类的实例,同样在B
类中也需要用到A类的实例,我把两个类是放在两个文件中,分别为a.h, a.cpp, b.h, b.
cpp,但是,问题是我无论如何也不能让编译器认识这是两个类。
请教高手,如何放置头文件才可以实现编译通过。
我的文件大概如下:
文件a.h
#ifndef a_h
#define a_h
class A
{
vector mylist;
}
#endif
文件b.h
#ifndef b_h
#define b_h
class B
{
public:
void print(A aa);
}
#endif |
|
h**o 发帖数: 347 | 14 请问instantiation应该放在哪个文件中?
现在遇到的问题是
template class A
声明在 A.h
定义在 A.cpp
实例在 A.cpp
class B
声明在 B.h
定义在 B.cpp
B要用到A
class C
声明在 C.h
定义在 C.cpp
C要用到B
我想实例化 A< list >,这句应该放在哪里好
如果放在C.cpp中,gcc 好像ignore了。。。 |
|
q****2 发帖数: 7 | 15 I have two class A and B as fllowing
class A {
public:
int i;
public:
A() : i(1) { }
};
class B : public A {
public:
int i;
public:
B() : A(), i(2) { }
};
A has data i, B has a new data i, in fact B has two int numbers. I want to
know how to use the i defined in A with a B object.
Thanks a lot. |
|
b***y 发帖数: 2799 | 16 For base classes, it is ok to have more virtual functions because derived
classes may need to customize these functions. For concrete classes, they
may have their own nonvirtual functions that are not supposed to be
overrided.
Also, if you declare a function as virtual, it can't be a inline function. |
|
l*****d 发帖数: 359 | 17 it seems that struct and class are equivalent in c++ except for that the
default access for the member of a class is private while for that of a
struct is public.
My question is: can a struct inherit from a class, and vise versa? |
|
b***y 发帖数: 2799 | 18 ☆─────────────────────────────────────☆
qr (非凡公子) 于 (Fri Apr 11 18:03:21 2008) 提到:
我想在一个class的constructor里面初始化某些数据,希望这些数据类型可以是float
或者double的,现在的问题是如果我把constructor写在xxx.h文件中,程序不报错。但
是如果单独写在xxx.cpp中,然后include xxx.h中的declartion,在主程序中再调用这
个xxx.h然后定义该class的一个实例,编程器总是报告link错误,说这个constrctor函
数是unresolved external symbol。如果把程序改成正常的class就没有这个问题,百
思不得其解,请高手赐教。
☆─────────────────────────────────────☆
jobseek (seeking+jobs) 于 (Fri Apr 11 18:23:00 2008) 提到:
这是template的毛病,
得把declaration and definit |
|
s*****k 发帖数: 604 | 19 我不是牛人,这个问题不需要牛人来解答
一个empty class 最小占一个byte,否则就没地址了
另外class里面的non-virtual member function 不会增加
class的size
vitual function的话会多一个 vtable |
|
I**********s 发帖数: 441 | 20 不等价. 如果在Base里declare, 在Derived里定义, 可以直接用Derived class的
instance. 现在必须在Derived的Derivative class里定义之. 此外根据其他相关class
的定义, 整个derivation structure都不一样. 总而言之, 差别大了. |
|
v*****r 发帖数: 2325 | 21 C is derived from from base class B
p is a pointer to class B
how to find out p point to B or C? |
|
s*****w 发帖数: 1527 | 22 long time ago it's
#ifdef WIN32
do_win_stuff()
#else UNIX
do unix_stuff()
...
how about
base class do_sth()
{
has all the functionality interfaces
}
class win_do_sth:public do_sth
class unix_do_sth:public do_sth |
|
f********f 发帖数: 475 | 23 第一次用Visual Studio .net 2005, 需要将一个算法程序从C变成C++. 其实就是很小
的改动, 原来是两个global的functions, 现在我将他们放到一个class里变成两个
static functins. 但是编译的时候告诉我
error C2061: syntax error : identifier 'class'
好象是不认识class这个identifier. 试了一下namespace, 也不认识, 怎么回事呢? 谢谢! |
|
v*****r 发帖数: 2325 | 24 yes. without explicity specify "access specifier ", it is
class derived: private base {
}
Although the constructors and destructors of the base class are not
inherited themselves, its default constructor (i.e., its constructor with no
parameters) and its destructor are always called when a new object of a
derived class is created or destroyed. |
|
s********z 发帖数: 5411 | 25 新手,请原谅!
我build的时候遇到两个这个error,“expected class name before "(" token”
第一个发生在 ~CDigiCam(); 这条line上。
第二个发生在 ~CCamLinkCam();
谁能帮我看看吗? 多谢!
第一个h file。
#pragma once
#ifndef CDIGICAM_H
#define CDIGICAM_H
#include
#include
#include
typedef unsigned char byte; /* 8-bit */
typedef unsigned short word; /* 16-bit */
class CDigicam
{
public:
CDigicam();
~CDigiCam(); *********这条line的error
int iXCamRes,
iYCamRes,
.... 阅读全帖 |
|
e****d 发帖数: 895 | 26 Declaration allows name lookup to find the entity.
Definition defines the entity.
A definition can also be a declaration.
You declare a static data member in a class and define it outside the class.
One definition rule doesn't allow you define a static data member
in a class becuase multiple includes will violate the ODR. |
|
s*i 发帖数: 388 | 27 刚开始学习hadoop,看到如下代码
JobConf conf = new JobConf(WordCount.class);
查了下doc,定义如下:
JobConf(Class exampleClass)
Construct a map/reduce job configuration.
这种 WordCount.class 的函数参数究竟是传了什么进去 JobConf 的ctor?
是这个WordCount的binary ? 还是一个instance?还是String? |
|
r*******y 发帖数: 1081 | 28 is this definition local to a file ? for example
// file 1.cpp
#include
using namespace std;
class mytest{
int i;
}
int main(){
return 0;
}
// file 2.cpp
#include
using namespace std;
class mytest{
int i;
}
Then I compile g++ -o 1 1.cpp 2.cpp
it is ok. So I just think that class definition should be
local to the file, or otherwise there should be
multidefinition error in this example, right ? Thanks. |
|
r****t 发帖数: 10904 | 29 But the linking works even when I made two definition of class to be
different:
//1.cpp
#include
using namespace std;
class mytest{
int i;
};
int main(){
return 0;
}
//2.cpp
#include
using namespace std;
class mytest{
float a1;
float a2;
};
$ g++ -o a.out 1.cpp 2.cpp
这个跟 standard 3.2.5 说的不一样 (each definition of D shall consist of the
same sequence of tokens;) 这个是仲么回事? |
|
X****r 发帖数: 3557 | 30 You need something like "struct X;" or "class X;" in forward declaration.
You also need this struct/class keyword along with the struct/class name
(called elaborated type specifier) if you want to specify a type name
shadowed by a function or variable name, e.g.
struct X {
int a;
};
int X() {
return 0;
}
int g = X(); // calls the function
// The 'struct' keyword is required here.
struct X x;
declare
unless |
|
O*******d 发帖数: 20343 | 31 Base class不应该知道derived class的任何东西。 |
|
c**********e 发帖数: 2007 | 32
> f *b = new f;
You can not use base class pointer to initialize derived class pointer. |
|
O*******d 发帖数: 20343 | 33 Base class不应该知道derived class的任何东西。 |
|
c**********e 发帖数: 2007 | 34
> f *b = new f;
You can not use base class pointer to initialize derived class pointer. |
|
c**********e 发帖数: 2007 | 35 【 以下文字转载自 JobHunting 讨论区 】
发信人: careerchange (Stupid), 信区: JobHunting
标 题: How to find out the memory layout of a class
发信站: BBS 未名空间站 (Mon Apr 2 22:12:45 2012, 美东)
How to find out the memory layout of a class without initiation of the class
? |
|
k**l 发帖数: 2966 | 36 I have a question of c++ programing habit,
I sometimes use list, map or other container to store user defined classes,
and use it later in member functions--say
std::list m_list;
When inserting a new element, I always have to fully create an element, then
call push_back or insert.
MyElement elem(1,2,"something"...);
m_list.push_back(elem);
And push_back would call copy constructor (I defined in MyElement class) to
duplicate the object.
After inserting, the elem itself is never used an... 阅读全帖 |
|
f********o 发帖数: 1163 | 37 class a():
def __init__(self):
self.aa = 1
def ab(self):
class b(c):
print self.aa #(这个地方想用a的aa值,而不是b的) |
|
p*******8 发帖数: 344 | 38 现在的问题是需要在跑任何代码之前,先把特殊几个用户定义的class先load进来,有
什么设置可以做到的?有没有什么call back可以用来做这些事的?好像java class
loading都是用到的时候才load,有没有强制load class的设置? |
|
B********e 发帖数: 1062 | 39 Try this:
class Animal {
virtual void processData(AnimalData &d)
{
//process common data for an animal
}
};
class Cat : public Animal {
virtual void processData(AnimalData &d)
{
Animal::processData(d);
//process cat specific data
}
};
class Dog : public Animal {
virtual void processData(AnimalData &d)
{
Animal::processData(d);
//process dog specific data
}
}; |
|
B********e 发帖数: 1062 | 40 class Animal {
virtual void processData(AnimalData &d) {
{
//process common data for an animal
processPrivateData(d);
}
protected:
virtual void processPrivateData(AnimalData &d) = 0;
};
class Cat : public Animal {
virtual void processPrivateData(AnimalData &d)
{
//process cat specific data
}
};
class Dog : public Animal {
virtual void processPrivateData(AnimalData &d)
{
//process dog specific data
}
}; |
|