小编Jam*_*mes的帖子

C++:运算符重载 - cout和cin - ostream函数,不能被引用 - 它是一个已删除的函数

我重载了一个cout和cin opeartor,当我尝试使用它时,它给了我一个像这样的错误:

1 IntelliSense: function "std::basic_ostream<_Elem, _Traits>::basic_ostream(const     std::basic_ostream<_Elem, _Traits>::_Myt &) 
[with _Elem=char, _Traits=std::char_traits<char>]" 
(declared at line 84 of "C:\Program   Files (x86)\Microsoft Visual Studio 12.0\VC\include\ostream") cannot be referenced -- it is a deleted function    
Run Code Online (Sandbox Code Playgroud)

这是我班级的头文件:

#pragma once
#include <iostream>

class Point2D
{
private:
    int m_X;
    int m_Y;
public:
    Point2D(): m_X(0), m_Y(0)
    {
    }

    Point2D(int x, int y): m_X(x), m_Y(y)
    {
    }

    friend std::ostream& operator<< (std::ostream out, const Point2D &point)
    {
        out << "(" << point.m_X << "," << point.m_Y << ")" …
Run Code Online (Sandbox Code Playgroud)

c++

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

C++:类型转换运算符重载 - Visual Studio 2013内部错误

我正在重载类型转换操作符,并在Visual Studio 2013中发生内部错误.

这是指数类的标题:

#pragma once
#include "Calc.h"
#include <iostream>

using namespace std;


class Exponent
{

private:
    int base;
    int exponent;
public:
    Exponent();
    Exponent(int a)
    {
        base = a;
    }

    int getBase()
    {
        return base;
    }


};

void printExp(Exponent e)
{
    cout << e.getBase() << endl;
}
Run Code Online (Sandbox Code Playgroud)

这是calc.h我写的将包含重载类型转换函数:

#pragma once
#include "Exponent.h"

class Calc
{
private:
    int acc;
public:
    Calc();
    Calc(int a);

    operator Exponent()  //this is where I get an error. 
    { 
        return Exponent(acc); 
    }


};
Run Code Online (Sandbox Code Playgroud)

这是主要功能:

#include "stdafx.h"
#include …
Run Code Online (Sandbox Code Playgroud)

c++ typecasting-operator visual-studio-2013

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

为什么Thread.Sleep()方法睡眠超过预期?

因此,我的程序基本上是创建Main的子线程并从用户获得一个整数作为输入,并通过将其计数为1000将该数字转换为milisecond.

但是在for循环中,当我输入数字5作为输入时,Thread.Sleep()会休眠大约10秒.

代码:

static void CallToChildThread()
{

     Console.WriteLine("How many seconds do you want this thread to rest?");
     int time = Convert.ToInt32(Console.Read());
     int mili = time * 1000;

     for (int i = 0; i < time; i++)
     {
         Console.Write(". ");
         Thread.Sleep(mili);
     }

     Console.WriteLine();

}
Run Code Online (Sandbox Code Playgroud)

因此,当我键入5时,代码将乘以5乘以1000并将5000存储在mili中.

但是,在for循环中,当执行Thread.Sleep(mili)时,它不会整整睡5秒,它会在循环中迭代一次后休眠10秒.

此外,当我用5000更改替换mili以使线程休眠5秒时,每次循环,并且它工作,但循环迭代超过我的预期.例如,这是我输入的输入:

How many seconds do you want this thread to rest?
5

. . . . . . . . . .      
Run Code Online (Sandbox Code Playgroud)

每次迭代时它都会正常计算5秒.但它迭代超过5.如果我键入5然后不应该for循环迭代5次并中止?只显示5个时期?

c# multithreading thread-sleep

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