- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有两个类,一个在另一个里面,我想在外部类构造函数的主体中构造内部类。我有我认为应该是正确的代码,但它不起作用。错误消息似乎告诉我没有与我的调用匹配的 VSL::VSL(),但它似乎是正确的原型(prototype)。
代码看起来像这样:
在标题中:
class VSL
{
VSL(vector<string> &v, string &s);
};
class KVTest
{
VSL vsl;
KVTest(int argc, char *argv[]);
};
在正文中:
KVTest::KVTest(int argc, char *argv[]) {
vector<string> v;
string s;
vsl(v, s);
}
此操作失败并显示以下错误消息:
src/util/kv-test/kv-test.cpp: In constructor 'KVTest::KVTest(int, char**)':
src/util/kv-test/kv-test.cpp:237: error: no matching function for call to 'VSL::VSL()'
src/util/kv-test/kv-test.cpp:112: note: candidates are: VSL::VSL(std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&, std::string&)
src/util/kv-test/kv-test.h:45: note: VSL::VSL(const VSL&)
src/util/kv-test/kv-test.cpp:347: error: no match for call to '(VSL) (std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&, std::string&)'
第237行是KVTest构造函数声明第 347 行是该构造函数中调用 vsl 构造函数的行第 112 行是 VSL 构造函数声明标题的第 45 行是 { 开始 VSL 类我没有 VSL 的显式复制构造函数
最佳答案
当您进入KVTest::KVTest
的主体时,vsl
已经初始化;你不能再次调用构造函数。但是没有默认(即零参数)构造函数,因此出现编译器错误消息。
你有两个选择:
VSL
声明默认构造函数。使用 constructor initialisation list 显式初始化 vsl
.这通常看起来像这样:
KVTest::KVTest(int argc, char *argv[])
: vsl(foo, bar)
{}
如果您需要执行涉及临时变量等的复杂初始化,那么您应该考虑编写一个返回 VSL
的私有(private)辅助函数。
关于c++ - 构造函数中的后期构造,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11059125/
总结 我需要在 Camel 服务器 in-modify-out 过程中构建一组统计数据,并将这些统计数据作为一个对象(单个 json 日志行)发出。这些统计数据需要包括: input file met
某个元素使用以下 CSS 功能产生了惊人的结果: 盒子阴影;边界半径;边框和背景上的 RGBA 颜色。 问题是前两个需要延迟 Firefox/Chrome/Safari 浏览器,第二个不兼容 IE8
在我的 Rails 应用程序中有这段代码: window.onload = -> $("#mycontainer").typewriter() $("#div1").fadeIn("slow"
我想检查我的 api 是否工作正常。我有一个只有 post 请求而没有 GET 的 api。 教程在这里:https://learn.microsoft.com/en-us/azure/applica
我想检查我的 api 是否工作正常。我有一个只有 post 请求而没有 GET 的 api。 教程在这里:https://learn.microsoft.com/en-us/azure/applica
我是一名优秀的程序员,十分优秀!