当我执行以下操作时:
template <typename T>
class Container
{
public:
class Iterator
{
friend bool operator==(const Iterator& x, const Iterator& y);
};
};
Run Code Online (Sandbox Code Playgroud)
gcc给了我以下警告和建议:
warning: friend declaration
'bool operator==(const Container<T>::Iterator&,
const Container<T>::Iterator&)'
declares a non-template function [-Wnon-template-friend]
friend bool operator==(const Iterator& x, const Iterator& y);
^
(if this is not what you intended,
make sure the function template has already been declared
and add <> after the function name here)
Run Code Online (Sandbox Code Playgroud)
我很确定这是一个新的警告,因为我总是这样做,从来没有任何问题.
有人可以解释为什么这是一个警告,它警告什么?
我可以使用该PEM_read_RSA_PUBKEY功能轻松读取 PEM文件。但是,我有一个已内置到可执行文件中的公钥,我不想制作临时文件。阅读此示例/教程:http : //hayageek.com/rsa-encryption-decryption-openssl-c/我想出了以下解决方案:
#include <openssl/rsa.h>
#include <openssl/pem.h>
#include <openssl/bio.h>
#include <QFile>
#include <QByteArray>
#include <stdexcept>
#include <cassert>
#include <cstring>
RSA* createRSA(const char* key)
{
RSA *rsa = nullptr;
BIO *keybio ;
keybio = BIO_new_mem_buf(key, -1); // !!!
if (!keybio)
{
throw std::runtime_error("Failed to create key BIO");
}
rsa = PEM_read_bio_RSA_PUBKEY(keybio, nullptr, nullptr, nullptr); // !!!
if(!rsa )
{
throw std::runtime_error("Failed to create RSA");
}
BIO_free(keybio); // !!!
return rsa;
}
int main()
{ …Run Code Online (Sandbox Code Playgroud) 根据包括Wikipedia在内的一些资料,实现二叉树的两种最常用的方法是:
第二个显然在内存使用和引用的位置方面优越。但是,如果您希望以某种可能使树不平衡的方式从树中插入和移除,可能会导致问题。这是因为此设计的内存使用量是树深度的指数函数。
假设您要支持此类插入和删除。如何实现树,以便树遍历可以充分利用CPU缓存。
我正在考虑为节点创建对象池并将它们分配到数组中。这样,节点将彼此靠近->因此具有良好的参考位置。
但是,如果节点的大小与缓存行的大小相同,这有意义吗?
如果您的L1行大小为64字节,并且访问的第一个成员std::vector<std::uint8_t>(64),则可能会在L1缓存中包含向量的全部内容。这意味着您可以非常快速地访问任何元素。但是,如果元素的大小与缓存行的大小相同怎么办?由于L1,L2和L3高速缓存的高速缓存行可能不会有很大差异,因此,似乎没有办法在此提供参考位置的帮助。我错了吗?还有什么可以做的?
我正在尝试在 Ubuntu 16.04 上使用Spring Tool Suite 3.8.3。启动后我收到此错误:
期间发生内部错误:“初始化 Java 工具”
详细消息:
在“初始化 Java 工具”期间发生内部错误。无法找到用于堆栈图生成的 Asm(正在查找“aj.org.objectweb.asm.ClassReader”)。需要生成编织代码的堆栈图,以避免在 Java 1.7 或更高运行时上编织类型 org.eclipse.jdt.core.search.SearchPattern 时在编织类时出现验证错误
我不得不承认,我不知道我应该在这里做什么,而且我在网上找不到任何指示。欢迎任何建议或提示。
我试过了:
import kotlin.Double.Companion.POSITIVE_INFINITY
import kotlin.Double.Companion.NaN
const val inf = POSITIVE_INFINITY
const val nan = NaN
Run Code Online (Sandbox Code Playgroud)
但我得到:
Const'val'初始化器应该是一个常量值
编辑:
我需要这样做的原因是因为Junit5的参数化测试:
@ParameterizedTest
@ValueSource(doubles = doubleArrayOf(nan, inf, -2* epsilon, 1.5, -0.5, 1.0 + 2* epsilon))
fun ensureNotAProbability(number: Double)
{
...
}
Run Code Online (Sandbox Code Playgroud)
由于Java注释的一些限制(在本SO答案中描述),传递给注释的东西只能是编译时常量.因此,我需要编译时NaN,正数和负数无穷大.
我尝试在 4K 显示器上使用 AsciidocFX 编辑器,但用户界面太小。
我尝试尝试这些设置,但似乎无法从应用程序内更改 UI 的比例。
vmoptions由于 AsciidocFX 是使用 JavaFX 框架编写的,因此我认为可以通过修改应用程序或从命令行传递一些标志来更改设置。这可能吗?
我很满意operator =,它由编译器自动合成.但我希望它是私有的,并且不希望使用该类型的页面长定义来膨胀我的代码
Foo& Foo::operator= (const Foo& foo)
{
if (this == &foo)
return *this;
member1_ = foo.member1_;
member2_ = foo.member2_;
member3_ = foo.member2_;
...
member1000_ = foo.member1000_;
return *this;
}
Run Code Online (Sandbox Code Playgroud)
拜托,有办法做到这一点吗?
例如,我想简化std::tr1::shared_pointer模板类.我想要一个别名std::tr1::shared_pointer.
但这不起作用:
#include <tr1/memory>
template <class T>
class SharedPointer : public std::tr1::shared_ptr<T>
{
};
int main(int argc, char *argv[])
{
SharedPointer<int> test(new int(5));
return 0;
}
Run Code Online (Sandbox Code Playgroud)
由于构造函数不是继承的.
有没有解决这个问题的模式?
假设我有这样的事情:
class Collection
{
private:
typedef std::vector< std::shared_ptr<Something> >::iterator Iterator;
std::vector< std::shared_ptr<Something> > data_;
public:
Iterator begin() {return data_.begin()}
Iterator end() {return data_.end()}
}
Run Code Online (Sandbox Code Playgroud)
当我使用一个Collection::Iterator实例时,我需要取消引用它一次,获取std::shared_ptr<Something>对象并再次获取Something对象.
但是如果我想制作std::shared_ptr<Something>一个实现细节,那么在一次解除引用后,我应该得到一个Something对象是合理的.
那是:
Collection collection;
Collection::Iterator it = collection.begin();
Something firstMember = *it; // instead of the current **it;
Run Code Online (Sandbox Code Playgroud)
我的问题是,我是否需要Collection从头开始将Iterator作为嵌套类并从这里实现随机访问迭代器所需的所有功能http://www.cplusplus.com/reference/std/iterator/或者是否存在一些众所周知的方法?可能是C++ 11?
我已经意识到,为了使快速排序工作,所有的无限性都必须是平等的.
换句话说,这样的标准是不够的:
class Entity
{
public:
float value() const;
bool valueIsInfinite() const;
};
class Criterium
{
bool operator()(Entity left, Entity right)const
{
if (left.valueIsInfinite())
return false;
return left.value() < right.value();
}
}
const Criterium criterium;
QVector<Entity> container;
qSort<container.begin(), container .end(), criterium>
Run Code Online (Sandbox Code Playgroud)
这种排序失败了,因为根据标准并非所有无穷大都是相等的.不平等取决于实体进入运营商的顺序.我发现,这样的排序失败了.
我需要这样的东西:
class Criterium
{
bool operator()(Entity left, Entity right)const
{
if (left.valueIsInfinite() && right.valueIsInfinite())
return false;
if (left.valueIsInfinite() && !right.valueIsInfinite())
return false;
if (!left.valueIsInfinite() && right.valueIsInfinite())
return true;
return left.value() < right.value();
}
}
Run Code Online (Sandbox Code Playgroud)
但是假设不是
float Entity::value() const; …Run Code Online (Sandbox Code Playgroud)