小编Bar*_*ran的帖子

1000个共享指针占用多少内存?

  1. (例如)1000个共享指针占用多少内存?
  2. 是16 x 1000字节吗?
  3. 32位和64位系统是否有所不同?

c++ smart-pointers shared-ptr c++11

4
推荐指数
1
解决办法
244
查看次数

为什么编译器将类函数作为非静态函数处理?

我正在更新C ++编程技能,并且正在阅读Stroustrup的书,以学习使用STL和现代C ++习惯用法进行编码。我决定从编写实用程序类开始,该类Date应该支持基本的日期代数。我的Useful::Date类有一些静态的功能,我想作为来电Date.is_bus_day()Date.plus_b_days()Date.plus_b_months()等。

但是,由于某种原因,C ++似乎认为此函数是非静态函数而不是类函数。我不知道为什么会这样。我知道静态方法只能访问类的其他静态成员。

日期类

#include <iostream>
#include <string>
#include <vector>

template<typename T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec)
{
    for (auto& el : vec)
    {
        os << el << ' ';
    }
    return os;
}

namespace Useful
{
    typedef int Day;
    typedef int Year;

    enum Month{
        January = 1,
        February = 2,
        March = 3,
        April = 4,
        May = 5,
        June = 6,
        July = 7,
        August …
Run Code Online (Sandbox Code Playgroud)

c++

1
推荐指数
1
解决办法
76
查看次数

Uniform_int_distribution &lt;&gt;和&lt;int&gt;有什么区别?

我是C ++的初学者。我想问一下:

std::uniform_int_distribution<> dis(1, 6);等于std::uniform_int_distribution<int> dis(1,6);

非常感谢。

c++ int distribution std uniform

0
推荐指数
1
解决办法
64
查看次数

正值递增时整数如何以负数结尾?

我只是写这段代码,但我不知道它是如何工作的。

为什么价值k会是负数?怎么样?

#include<iostream>
using namespace std;
int main()
{
    int k=1,j=0;
    while(k>j)
    {
        j=k;
        k++;
    }
    cout<<j<<"\n"<<k;
}
Run Code Online (Sandbox Code Playgroud)

它显示了整数的范围

c++

-2
推荐指数
1
解决办法
87
查看次数

标签 统计

c++ ×4

c++11 ×1

distribution ×1

int ×1

shared-ptr ×1

smart-pointers ×1

std ×1

uniform ×1