#include <iostream>
#include <fstream>
#include <vector>
#include <cassert>
class A {
public:
A() {}
};
class B : public A {
public:
B() {}
~B() { }
private:
std::string m_value;
};
class GoodB : public B {
public:
GoodB() : m_v(new char(10000000)) {}
GoodB(const char* f) : m_file(f, std::ios_base::in) {
if(!m_file.is_open()) throw std::string("Couldn't open file..\n");
std::string line;
while(std::getline(m_file, line)) {
m_info.push_back(line);
}
}
void doIt( GoodB const&b) {
if(b.isOpen()) {
}
}
~GoodB() { assert((!isOpen()) && "open file: "); }
private:
char *m_v;
std::fstream m_file;
std::vector<std::string> m_info;
bool isOpen() const { return !m_info.empty(); }
};
void test() {
int i = 0;
for(;;) {
try {
++i;
if(i % 10000 == 0) std::cout << "count i: " << i << std::endl;
GoodB b;
} catch(...) {
return ;
}
}
}
void test2(char *filename) {
try {
GoodB b(filename);
GoodB d(filename);
b.doIt(b);
} catch(std::string msg) {
std::cout << msg;
}
}
int main(int argc, char** argv) {
if(argc <= 1) return 1;
test2(argv[1]);
std::cout << "exit!!!\n";
return 0;
}
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步