我知道test(m,t)的t如果在调用之前就申请空间的话不会有问题,但是我的程序的申请空间的大小要在test函数里面才能确定
解决方案 »
- 请问,只有VS2008英文版才能用的起Visual C++ 2008 Feature Pack吗?
- 高手救命,十万火急,IXMLDOMDocument::appendchild报access violation错误
- 开发网络游戏对硬件编程的考虑
- mixersetcontroldetails 如何设置录音来源为MicroPhone
- 如何检测 某个new出来的对象什么时候被释放,内存断点设上怎么没用呢,内存改写的时候并部中断
- 如何操作网页??
- 谁有把系统托盘小图标右键菜单变成xp风格的类
- 最后的奋斗!(新手)
- 救命啊.........关于setmapmode
- 请大家一起来讨论一下:如何编程实现虚拟局域网?
- 如何在html页面中加入dll,或ocx呀???????我好急呀
- CreateIC("DISPLAY",NULL,NULL,NULL)? 什么意思?
{
num = 3;
p = new int [num];
for( int i=0; i<num; i++ )
{
p[i] = i;
}
}
这个我当然想过了,可是编译器总是说有问题。MD
E:\Test\TestDlg.cpp(177) : error C2440: '=' : cannot convert from 'int *' to 'int ** '
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
E:\Test\TestDlg.cpp(180) : error C2440: '=' : cannot convert from 'int' to 'int *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
E:\Test\TestDlg.cpp(201) : error C2664: 'test' : cannot convert parameter 2 from 'int *' to 'int ** '
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
Error executing cl.exe.Test.exe - 4 error(s), 0 warning(s)
void test( int &num, int **p )
{
num = 3;
*p = new int [num];
for( int i=0; i<num; i++ )
{
(*p)[i] = i;
}
}
void CTestDlg::OnOk()
{
// TODO: Add your control notification handler code here
int m;
int *t=NULL; test(m,&t);//此时应传指针的地址
}
或者改成这样:
void test( int &num, int** p )
{
num = 3;
*p = new int [num];
for( int i=0; i<num; i++ )
{
p[i] = i;
}
}
{
num = 3;
*p = new int [num];
for( int i=0; i<num; i++ )
{
(*p)[i] = i;
}
}
void CTestDlg::OnOk()
{
// TODO: Add your control notification handler code here
int m;
int *t=NULL; test(m,&t);
delete[]t;
}
或者改成这样:
void test( int &num, int** p )
{
num = 3;
*p = new int [num];
for( int i=0; i<num; i++ )
{
p[i] = i;
}
}
void test( int &num, int* &p ) //指针的引用
{
num = 3;
p = new int [num];
for( int i=0; i<num; i++ )
{
p[i] = i;
}
}
///没有什么问题呀!!
害的我白花了半天的时间.
散分。