我有一个疑问,下面的函数可以接收类型A的对象或派生类型的东西.
A *copyToHeap(A &obj) {
A *ptr=new A(obj);
return ptr;
}
Run Code Online (Sandbox Code Playgroud)
如果我们这样称呼它:
//B inherits from A
B bObj;
B *hPtr=copyToHeap(bObj);
Run Code Online (Sandbox Code Playgroud)
指向的对象hPtr实际上是A型还是B型?这样做安全吗?
我有一个50MiB的小分区,格式为ext4,只有一个包含一组照片的目录,安装在/ mnt/tmp上.
然后我statvfs()用来计算分区中的已用字节,并lstat()用于计算里面每个文件的大小,为此我编写了这个程序:
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <sys/statvfs.h>
#include <stdint.h>
#include <string.h>
#include <dirent.h>
#include <stdlib.h>
//The amount of bytes of all files found
uint64_t totalFilesSize=0;
//Size for a sector in the fs
unsigned int sectorSize=0;
void readDir(char *path) {
DIR *directory;
struct dirent *d_file; // a file in *directory
directory = opendir (path);
while ((d_file = readdir (directory)) != 0)
{
struct stat filestat;
char *abPath=malloc(1024);
memset(abPath, 0, 1024);
strcpy(abPath, …Run Code Online (Sandbox Code Playgroud)