我写了一个与此类似的函数:
class abc {
private :
int m_var ;
public :
int func() { return m_var ; }
};
Run Code Online (Sandbox Code Playgroud)
当我尝试打印func()使用abc对象指针时gdb,它给出错误:
**Cannot evaluate function -- may be inlined**
如何从内联函数中打印值?
我想在 gdb 执行时添加一些断点。如何暂停运行 gdb 并插入断点并从那里继续。我试过 ctrl+z ,它杀死了 gdb 进程。
我打开了一个文件
FILE *fp = fopen("file.txt","r");
fclose(fp);
Run Code Online (Sandbox Code Playgroud)
场景是我忘了给fp
现在分配null 我想检查这个文件是否打开或者没有使用相同的fp指针
class abc {
int x ;
};
int main()
{
abc *A = new abc ;
cout<< static_cast<void*>(A) << endl ;
delete A ;
cout<< static_cast<void*>(A) << endl ;
abc *B = new abc ;
cout<< static_cast<void*>(B) << endl ;
delete B ;
cout<< static_cast<void*>(B) << endl ;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
为什么它打印相同的地址,即使我删除了旧内存.
即使我删除后指定null,它也会打印相同的地址.
甚至A和B的地址也是一样的.
实时场景:
Function1 ->
arr[p] = new X
ptr1 = arr[p]
using ptr1
Function2 ->
ptr2 = arr[p]
delete ptr2
arr[p] = new X ( new data) …Run Code Online (Sandbox Code Playgroud) 让我的parent班级成为;
class parent {
virtual void printx () { cout<< "parent" ; }
}
Run Code Online (Sandbox Code Playgroud)
情况1:
class child : public parent {
virtual void printx() { cout<< " child" ; }
}
Run Code Online (Sandbox Code Playgroud)
案例2:
class child : public parent {
void printx() { cout<< " child" ; }
}
Run Code Online (Sandbox Code Playgroud)
如果我virtual在child类中省略了printx案例2中的函数,有什么区别吗?
示例文件名是
abc.edf.xdc
pqe.ide.xdc
rm -rf "*.\*.xdc" 不管用
list<abc*> mylist ;
for( it = mylist.begin() ; it != mylist.end() ; ++it ) {
cout<<(*it)->getB()<<endl ;
if(*it == "0x9090" ) {
mylist.remove(*it);
}
}
Run Code Online (Sandbox Code Playgroud)
我在列表中插入了4个abc类对象,当我使用某些条件从列表中删除/擦除元素时,它会在下一次迭代中导致分段错误.