Cpp文件包括,同时也可以在其中调试
Cpp file including while also able to debug in it
在线程池实现中:
有一个threadpool.h,它有一个虚拟的类threadpool。
class ThreadPool {
funcX (){} = 0
...
}
// ThreadPoolImpl not defined or declared in this file.
在相应的threadpool.cpp中,有继承自threadpool的实现threadpoolImpl。
//include threadpool.h header.
class ThreadPoolImpl : public ThreadPool {
funcX() {....}; // The function I want to debug inside.
}
我问题:在我的main函数中:如果我只包含threadpool.h,那么由于缺少threadpoolImpl定义,我得到
incomplete type not allowed error.
如果我包含threadpool.cpp而不是threadpool.h,我得到链接错误,因为threadpool.cpp被编译两次。为了解决这个问题,我从我的项目中删除了threadpool.cpp。但是,这样我就不能用断点调试threadpool.cpp了。
请有人告诉我是否可以使用threadpoolImpl,同时也能够在其中调试(与VS IDE工具),或者我必须重写它?
您应该创建一个ThreadPoolImpl .h并将类ThreadPoolImpl的定义添加到其中。在main.cpp中,你只需要包含threadpoolImpl.h。
threadpoolImpl.h:
#include <threadpool.h>
class ThreadPoolImpl : public ThreadPool {
funcX(); // The function I want to debug inside.
}
threadpoolImpl.cpp:
void ThreadPoolImpl::funcX()
{
//debug here
}
看起来ThreadPool在你的设计中是一个接口。有一些更好的工具,如设计模式,可以改进您的实现。
你让它听起来像你是#include
的threadpool.cpp。不要这样做,只要确保它实际上是解决方案/项目的一部分,它显示在解决方案资源管理器中,并且正在编译。
相关文章:
- static_assert在宏中,但也可以扩展到可以用作函数参数的东西
- C++有什么方法可以在既不调用函数模板也不提供其模板参数的情况下引用函数模板?
- 通过将其中一个模板更改为 muliset 后,我可以在 PBDS 排序集上使用计数功能<int>less_equal<int>
- 斯塔克,堆栈,也可以在底部和顶部添加整数
- 如何实现唯一 id 队列,其中元素可以在 C++ 中"bumped"到顶部?
- 在不工作的情况下为数组分配指针,但反过来也可以
- 是否可以检索与柯南包管理器一起打包的库的源代码,以便在其中进行调试?
- "fixed"大小的向量在 c++ 中也可以具有假大小(与内存大小相比)吗
- C :宏参数可以在其中有空间吗?
- 拥有 std::map 的最佳方式,我可以在其中定义如果没有键时返回的内容
- C++,我可以在其中找到 gcc 编译器标准库的实现文件
- C++中是否有类似于 Java 的 CompareTo 方法,您可以在其中对数据类型使用 > < = 操作
- 是否有一个 c++ 矩阵库,我可以在其中索引具有非连续向量的矩阵,如 R 中的矩阵
- 如何获取绑定到我正在运行的控制台窗口的进程列表,这些进程也可以在 Windows 2000 中工作?
- Cpp文件包括,同时也可以在其中调试
- 在DLL中使用新的Vista线程池API也可以在XP中加载(在XP中不使用线程池代码)
- 我想在写入过程完成后从二进制文件中读取数据,也可以在没有写入过程的情况下读取数据
- c++中的委托构造函数可以在函数体中调用,也可以在初始化列表中调用
- 我想创建一个函数,我可以在其中输入一个字符串,它会输出一个混乱的字符串版本
- 是否也可以在数组中动态删除内存?