openKylin论坛

 找回密码

如下简单的C++代码为何出错? [复制链接]

  1. #include <iostream>
  2. class A{
  3.         public:
  4.                 A():root(NULL){}
  5.                 int *root;
  6.                 void Search(int* i,int* j=root){}
  7. };              

  8. int main(int argc,char **argv)
  9. {      
  10.         A a;
  11. }
复制代码
main.cpp:5:8: 错误:对非静态数据成员‘A::root’的无效使用
main.cpp:6:29: 错误:从这个地方

楼主
发表于 2013-5-31 20:26:13
回复

使用道具 举报

如下简单的C++代码为何出错? [复制链接]

  1. void Search(int* i,int* j=root){}
复制代码
默认参数一般是常量表达式吧,像你这样应该不行。
沙发
发表于 2013-5-31 20:57:50
回复

使用道具 举报

openKylin

GMT+8, 2024-5-16 03:56 , Processed in 0.019068 second(s), 17 queries , Gzip On.

Copyright ©2022 openKylin. All Rights Reserved .

ICP No. 15002470-12 Tianjin

快速回复 返回顶部 返回列表