下述链接给出的文章解释了为什么在类 Unix 系统下将程序主函数定义为 "void main(void)" 是错误的: void main(void) - the Wrong Thing 文章的要点如下: [quote] 1. Because the standard says so. 2. Because the startup routines that call main could be assuming that the return value will be pushed onto the stack. If main() does not do this, then this could lead to stack corruption in the program's exit se...
by MMMIX - C/C++ - 2007-06-03 09:28:54 阅读(3096) 回复(9)
一个小程序,一个类的内部定义了operator==比较运算符 > cat t.cpp struct a{ int x; bool operator==(const a& ia){return x==ia.x;} }; bool f(const a& ia, const a& ib){ return ia==ib; } int main(int argc, char *argv[]) { return 0; } 在solaris8(gcc2.95),devcpp4992, linux gcc 4.1.2下面编译都得到下面这样的错误: > gcc t.cpp t.cpp: In function `bool f(const a &, const a &)': t.cpp:6: ...
class A { public: virtual void sleep() const = 0; } 我原来的理解是:这就是用“=0”表示函数体是空的。 但是又发现VC支持: class A { public: virtual void sleep() const = 0{ int i}; } 似乎我原来的理解不对。 这个=0究竟准确含义是什么呢?
A)用const替代宏可以让编译器进行安全检查; B)一个const类对象只能调用其const成员函数,不能调用非const成员函数; C)const成员函数与同名,同返回值,同形参列表的非const成员函数属于重载; D)推荐使用以下方法定义类成员数组 class A { const size_t SIZE = 100; int _array[SIZE]; } 只知道A是对的....其他的就:emn22:
void CALL sort(int n, const double data[], int index[]) 这个CALL有什么意义
class A{ public: void copy(const A& a); private: int t; }; void A::copy(const A& a){ t=a.t;} 这里A::copy为什么能能访问a对象的私有成员t? 请大侠解答!先谢了! :>
定义了void fun(const int i)与 void fun(int i) 编译出错 提示:fun(const int )已经存在。
有如下类
class String {public: String(const char *initValue = ""); String(const String &rhs); ~String(); String& operator=(const String &rhs); const char& operator[](int index) const; char& operator[](int index);......};
和如下语句
String s;
..
...
cout <
void hello(void*arg) { char*kk="hello"; arg=(void*)kk; return NULL; } main() { void*k; hello(k); char *k2=(char*)k; printf("%s",k); exit(0); } when running ,I get 8Z@ ,not hello,why? thanks for looking at my question