Alexander_zero 2019-06-02 22:56 采纳率: 100%
浏览 743
已采纳

Visual Studio 2019复制粘贴的代码划红线,但是照着重打一遍就能跑了?这是为什么?

注释部分和下面是一样的
这就是报错场景

pch.h文件:

class Clock
{
private:
    int hour;
    int minute;
    int second;
public:
    void SetTime(int h, int m, int s);
    Clock(Clock& c);
    Clock(int h, int m, int s);
    ~Clock(void);
    void ShowTime();
};

pch.cpp文件

#include "pch.h"
#include<iostream>
using namespace std;
Clock::Clock(Clock& c) 
{
    hour = c.hour;
    minute = c.minute;
    second = c.second;
    cout << "The new clock: ";
    ShowTime();
    cout << " is copy constructed" << endl;
}
Clock::Clock(int h, int m, int s) 
{
    hour = h;
    minute = m;
    second = s;
    cout << "The new clock: ";
    ShowTime();
    cout << " is constructed!" << endl;
}
Clock::~Clock(void) 
{
    cout << "The clock: ";
    ShowTime();
    cout << " is destructed" << endl;
}
void Clock::SetTime(int h, int m, int s)
{
    hour = h;
    minute = m;
    second = s;
}
void Clock::ShowTime() 
{
    cout << hour << ":" << minute << ":" << second;
}

clock.cpp文件:

#include "pch.h"
#include <iostream>
using namespace std;
Clock Ring(Clock c)
{
    c.ShoweTime();
    cout << "Clock is ringing!" << endl;
    return c;
}
//Clock Ring(Clock c)
//{
//  c.ShowTime();
//  cout << "Clock is ringing!" << endl;
//  return c;
//}
void main()
{
    Clock c1(11, 20, 30);
    c1.ShowTime();
    cout << endl;
    Ring(c1);
    system("pause");

}

  • 写回答

2条回答 默认 最新

  • threenewbee 2019-06-03 09:49
    关注

    能运行就可以,有时候ide在解析符号,还没有解析完整,于是会有报错提示的误报。关键能编译就说明是对的

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
  • ¥50 汇编语言除法溢出问题
  • ¥65 C++实现删除N个数据列表共有的元素
  • ¥15 Visual Studio问题
  • ¥15 state显示变量是字符串形式,但是仍然红色,无法引用,并显示类型不匹配
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波