ChinaUnix.net
相关文章推荐:

只有静态常量整型数据成员才可以在类中初始化

代码如下: #include #include #include #include #include using namespace std; class base { public: int name; }; class A { protected: static base user[5]; static int ID; static int age; }; //这里如何给静态数据成员user[5]初始化? int A::ID = 5; int A::age = 5; class B : public A { public: int getID() const { return ID; } ...

by chzht001 - C/C++ - 2006-09-09 01:52:29 阅读(4555) 回复(10)

相关讨论

[code] typedef map;Map; class T { private: static Map m; }; [/code] Map初始化后将不会再被修改

by karabiner - C/C++ - 2004-09-13 10:46:07 阅读(2679) 回复(1)

有一个静态的“引用”成员,要命的是,在初始化之前需要先执行的一个静态函数,这样能保证初始化的正确。。。 我该如果保证这个初始化的顺序呢。。。。 谢谢!

by Tanacore - C/C++ - 2008-05-30 10:28:36 阅读(1464) 回复(3)

定义了一个color,它有一个静态成员static vector; _Ri,此vector向量需要依靠外部文件输入,所以不能简单的初始化(如:char* Color::_white="test";等),静态成员一般好像不用构造函数初始化(我是自学C++,且是初学,不知这么说是否恰当),如果不采用构造函数,我不知道该如何进行;如果采用构造函数,每次编译不能通过,提示我: error LNK2001: unresolved external symbol "private: static class std::vecto...

by vvfei - C/C++ - 2004-11-02 23:55:48 阅读(1454) 回复(5)

定义了一个: class mthread{ pthread_t tid; static int nr_thread; static pthread_mutex_t mutex; /* mutex for nr_thread */ public: mthread(); virtual int start() = 0; virtual int stop() = 0; virtual ~mthread(){}; int running(){ return tid != 0;}; }; 然后在某个.cpp初...

by vincent339 - C/C++ - 2006-10-01 12:28:44 阅读(2642) 回复(4)

[code] class foo { public: int a[2]={1,2}; }; [/code] 编译错误.

by book11 - C/C++ - 2006-08-24 22:16:38 阅读(1448) 回复(7)

template; class Buffer { T v; int sz; public: buffer():sz(i){} } 请问sz(i)的意思是什么?是不是将sz赋值为i? 是不是所有的成员可以如此初始化?还是有特定的使用限制?

by nicksean - C/C++ - 2003-07-01 10:10:25 阅读(1000) 回复(4)

JAVA常量初始化可以放到构造函数执行,不一定是在声明的时候初始化。而且常一般是声明为静态的,但是如果声明为静态的,则一定要给初始值,而不能在构造方法给值。 本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u2/64924/showart_2064526.html

by sytrydor - Java文档中心 - 2009-10-05 20:30:48 阅读(957) 回复(0)

[code] #include ; using namespace std; template; class A { public: enum{ number=10 }; static int a[number]; public: void dump() { for (int i=0; i;::number; i++) cout<; int A;::a[A;::number]={1}; int main() { A; a; a.dump(); return 0; } [/code] 在C++ builder 6.0运行正常,而hp-unix上aCC...

by wangxg2 - C/C++ - 2004-08-06 08:55:23 阅读(2260) 回复(6)

我记得静态变量是必须初始化的,而下面三段代码 #include using namespace std; class test { public:     static int x; }; int test::x = 0; int main() {     test::x = 1;     return 0; } #include using namespace std; class test { public:     static int x; }; //int test::x = 0; int main() { /...

by zhongyj - C/C++ - 2008-05-19 10:29:39 阅读(6346) 回复(2)

class Book{ Book(int i){ System.out.println("Creating Book "+i); } } public class InitTest{ private int i; private Book book1=new Book(1); public int getI(){ return i; } public static void main(String[] args){ System.out.println(new InitTest().getI()); } public static Book book2=new Book(2); } 首先注释掉main方法的println语句...

by biaoflying - Java文档中心 - 2008-03-18 09:23:17 阅读(485) 回复(0)