尝试创建一个std::shared_ptr以a std::shared_ptr作为参数的对象,导致"没有匹配的构造函数来初始化'object'"编译错误.
我的代码如下:
// Sidebar Widgets
_widgets.sideBarWidgetLeft = std::make_shared<SideBarWidget>();
_widgets.sideBarWidgetLeft->hide();
_widgets.sideBarWidgetRight = std::make_shared<SideBarWidget>();
_widgets.sideBarWidgetRight->hide();
// Pointer Test
CalibrationManagementWidget* test = new CalibrationManagementWidget( _widgets.sideBarWidgetLeft, 0 );
// Sidebar Left
_widgets.calibrationManagementWidget = std::make_shared<CalibrationManagementWidget>( _widgets.sideBarWidgetLeft, 0 );
_widgets.calibrationManagementWidget->hide();
_widgets.cameraWidget = std::make_shared<CameraWidget>( 0, VISUALISATION_TYPE_NORMAL );
_widgets.cameraWidget->hide();
Run Code Online (Sandbox Code Playgroud)
虽然"指针测试"编译得很好,但"侧边栏左侧"下的线条会产生命名错误.有没有什么我做错了实例化或一般不可能这样做?
这是(一个)错误消息:
/usr/include/c++/5.4.0/ext/new_allocator.h:120: Error: no matching constructor for initialization of 'CalibrationManagementWidget'
{ ::new((void *)__p) _Up(std::forward<_Args>(__args)...); }
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
Run Code Online (Sandbox Code Playgroud)
编辑:
根据要求,我将发布一些片段,其中也包含CalibrationWidget的构造函数.
calibrationwidget.h
...
Q_INVOKABLE CalibrationManagementWidget(QWidget* parent = 0 , VisualisationType visuType = VISUALISATION_TYPE_TRANSLATOR);
CalibrationManagementWidget( std::shared_ptr<SideBarWidget> sideBarWidget, …Run Code Online (Sandbox Code Playgroud) 我知道人们unordered_set会在不关心集合中元素的顺序时使用它们。但是,当我在C ++ Shell上运行示例程序时
#include <iostream>
#include <unordered_set>
#include <string>
int main()
{
std::unordered_set<std::string> inputSet;
inputSet.insert("Hello world");
inputSet.insert("Abcdef");
inputSet.insert("This is the test string...");
for(const auto &val : inputSet)
std::cout << val.c_str() << std::endl;
return 0;}
Run Code Online (Sandbox Code Playgroud)
它给我
This is the test string...
Abcdef
Hello world
Run Code Online (Sandbox Code Playgroud)
而且我尝试将其运行3或4次,它仍然给我相同的输出,这意味着有一种方法unordered_set可以确定插入顺序。
有人可以解释如何unordered_set确定插入顺序吗?
抱歉,如果之前曾有人问过我,我已经在网上搜索了一段时间,但找不到该问题的具体答案。提前致谢。
我只是尝试在C++中使用do while循环,而我想出了在do while循环中执行多项操作之后的括号内的描述或其他任何内容的描述.所以这是我最初的逻辑:我已经设置了password变量和input变量.如果两个东西匹配,那么它将退出循环并输出"正确的密码",否则它会继续回到循环,输出"错误的密码",所以它继续.这是我的代码:
// do while
#include<iostream>
using namespace std;
int main(){
int input, password=19960819;
do{
cout << "Type your password:" ;
cin >> input;
}while(input!=password && cout << "wrong password" << endl);
cout << "correct password" << endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我期待即使我输入了正确的答案,我仍然会输出"错误的密码".我认为那个cout << "wrong password" << endl部分总是会返回true,无论如何都应该执行,唯一的因素就是input!=password部分.然而,结果实际上是完美的,这不是我所期待的......任何人都可以解释逻辑吗?我正在挑战自己不使用if或其他逻辑,而只是使用do while逻辑来达到这个结果,但我不明白为什么它现在正在工作...
我无法理解这个三元运算符的转换逻辑(这里是一个例子):
#include <iostream>
#include <typeinfo>
#include <unistd.h>
#include <cxxabi.h>
#include <climits>
template<typename T>
struct singletime
{
private:
T value;
public:
T& operator()() {return this->value;}
operator const T& () const {return value;}
unsigned char flag_needed_for_all_types;
};
static void getvalue1 (uint64_t value, const char *call)
{
std::cout << call << ": \t" << value << std::endl << std::endl;
}
#define getvalue(x, str) \
std::cout << typeid(x).name() << std::endl; \
getvalue1(x, str);
int main (int argc, char *argv[])
{
bool flag = true; …Run Code Online (Sandbox Code Playgroud) 阅读hana的教程,我想知道如何static_assert按预期工作:
template <typename Any>
auto switch_(Any& a) {
return [&a](auto ...cases_) {
auto cases = hana::make_tuple(cases_...);
auto default_ = hana::find_if(cases, [](auto const& c) {
return hana::first(c) == hana::type_c<default_t>;
});
static_assert(default_ != hana::nothing,
"switch is missing a default_ case");
// ...
};
}
Run Code Online (Sandbox Code Playgroud)
文档明确声明default_不是constexpr对象,因此,即使operator!=这些类型的重载是constexpr函数,表达式default_ != hana::nothing也不能是常量表达式,因为它的一个参数不是.
教程说:
请注意我们如何在没有任何内容的情况下使用static_assert进行比较的结果,即使它
default_是一个非constexpr对象?大胆地说,Hana确保在运行时没有丢失编译时已知的信息,这显然是案例存在的default_情况.
教程在该段落中引用了什么,或者该表达式如何工作?
我希望每个会话只显示一次弹出窗口,一段时间后过期.有人能帮我吗?
function PopUp(){
$('.home-popup').fadeIn(500);
}
setTimeout(function(){
PopUp();
},1000); // 1000 to load it after 1 second from page load
$('.close-popup-btn').click(function() {
$('.popup').fadeOut(300);
});
Run Code Online (Sandbox Code Playgroud) 这是更改图像对比度和亮度的简单程序。我注意到,还有另一个程序,但有一个简单的区别:saturate_cast已添加到代码中。而且我不知道执行此操作的原因是什么,并且无需转换为无符号字符,或者uchar两个代码(使用saturate_cast<uchar>和不使用此代码)都输出相同的结果。我感谢任何人的帮助。
这是代码:
#include "opencv2/imgcodecs.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <iostream>
#include "Source.h"
using namespace cv;
double alpha;
int beta;
int main(int, char** argv)
{
/// Read image given by user
Mat image = imread(argv[1]);
Mat image2 = Mat::zeros(image.size(), image.type());
/// Initialize values
std::cout << " Basic Linear Transforms " << std::endl;
std::cout << "-------------------------" << std::endl;
std::cout << "* Enter the alpha value [1.0-3.0]: ";std::cin >> alpha;
std::cout << "* Enter the beta value [0-100]: "; …Run Code Online (Sandbox Code Playgroud) 出于教育目的,我今天早些时候实现了一个包装类,定义如下(这取自一本书):
#ifndef WRAPPER_H
#define WRAPPER_H
template<class T>
class Wrapper
{
public:
Wrapper()
{ dataPtr = 0; }
Wrapper(const T& inner)
{
dataPtr = inner.clone();
}
Wrapper(const Wrapper<T> &original)
{
if (original.dataPtr != 0)
dataPtr = original.dataPtr->clone();
else
dataPtr = 0;
}
Wrapper &operator =(const Wrapper<T> &original)
{
if (this != &original)
{
if (dataPtr != 0)
delete dataPtr;
dataPtr = (original.dataPtr !=0) ? original.dataPtr->clone() : 0;
}
return *this;
}
~Wrapper()
{
if (dataPtr != 0)
delete dataPtr;
}
T …Run Code Online (Sandbox Code Playgroud) 我从阅读转换int到long long int正在促销,因此认为不应该有任何问题,因为没有数据丢失,不像反之亦然转换.
但是当我将两个int大的值相乘并存储它时long long int,它会显示负数.
例如:
int a=1000000, b=1000000;
long long int c=a*b;
cout<<c;
Run Code Online (Sandbox Code Playgroud)
上面的代码给了我一个负值.有人可以解释原因吗?
如何make_shared计算时间,分配不同的区域而不重复循环?
我有以下代码:
for( unsigned int count = 0; count < demandedSize; ++count )
{
m_connectionList.push_back( std::make_shared< Foo >( m_ip, m_port ));
}
Run Code Online (Sandbox Code Playgroud)
如何在没有循环的情况下缩短这个?
我知道std::vector接收第二个参数const T&,但在这种情况下,所有shared_ptrs都指向同一个地址(值被复制).
std::vector< std::shared_ptr<Foo> > vet( demandedSize, std::make_shared<Foo>( m_ip, m_port ) );
Run Code Online (Sandbox Code Playgroud)
如何执行make_shared计数时间,结果分配不同的区域而不重复循环