auto

    0热度

    1回答

    现在我正在学习存储类here。他似乎也解释了自动存储类和寄存器存储类的相同情况。他在两者之间唯一的区别在于寄存器存储类存储在CPU寄存器中。这些存储类之间有什么区别吗?寄存器存储类的任何用途?在某些C编译器中,默认情况下是Register关键字? register int x = 5; auto int y = 3;

    1热度

    1回答

    我正在用C++编写一个简单的垃圾回收器。我需要一个单例类GarbageCollector来处理不同类型的内存。 我使用了迈尔的单身模式。但是当我尝试调用实例时,会出现一个错误: error: ‘GarbageCollector::GarbageCollector(const GarbageCollector&)’ is private GarbageCollector(const Gar

    4热度

    2回答

    考虑以下示例,其中在取消引用基指针期间发生对象切片。 #include <stdio.h> class Base { public: virtual void hello() { printf("hello world from base\n"); } }; class Derived : public Base{ public:

    4热度

    2回答

    我想知道在C++中是否有一个宏或语言元素表示与函数中的返回值相同的类型。 例如: std::vector<int> Myclass::CountToThree() const { std::vector<int> col; col.push_back(1); col.push_back(2); col.push_back(3); return c

    0热度

    2回答

    我最近阅读的一些帖子声称for(const auto &it : vec)与使用较长的迭代器语法for(std::vector<Type*>::const_iterator it = vec.begin(); it != vec.end(); it++)相同。但是,我遇到this post,说他们不一样。 目前,我试图擦除for循环中的一个元素,使用后,并想知道是否有任何方法将const auto

    0热度

    1回答

    尽可能多地使用auto是否是一个好主意,因此更改代码中的数据类型更灵活?就像如果你使用一堆基于范围的for循环一样,总是使用auto会很有效率,所以你永远不必回去改变for循环的数据类型?

    2热度

    4回答

    什么是auto*的类型扣除规则? 考虑以下几点: int x = 64; int* px = &x; auto* v1 = &x; // auto => ??? ok v1 is int* ... auto* v2 = px; // auto => ??? is v2 int* ? auto* v3 = &px; // auto => ??? is v3 int** ? 只是为了澄清

    1热度

    1回答

    将GMP和C++ 11结合使用时,我遇到了一些小问题。 示例程序: #include <gmpxx.h> int main() { mpz_class a,b; //ok auto c = a+b; //ok (?) c = 0; //error } 错误消息: error: no match for 'operator=' (operand types

    -1热度

    2回答

    [现代有效的C++]说: template<class T> void f(T t){} int main(){ f({1,2,3}); } 将失败的编译,因为当模板实例,T的类型必须是已知的,而在这里{1,2,3}的支撑,初始化列表。应该解决,如: auto x={1,2,3};//auto deduces x to std::initializer_list f(x);

    0热度

    1回答

    我想写一个函数,它会根据某些条件返回我String,Int,Float。使用C11。尝试过几个已经提到的东西,不适用于模板/汽车。如果该函数只有一个返回,那么它现在就罚款。当我添加另一个返回说字符串,编译错误。错误:从int无效转换为char* template<typename T> T getProperty(int field,Json::Value root) { for(i