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

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在解析符号,还没有解析完整,于是会有报错提示的误报。关键能编译就说明是对的

    已采纳该答案
    评论
    解决 无用
    打赏 举报
  • 飞天神龟 2019-06-03 11:36

    如果有遇到代码没错误,但是有红色下划线,可以在项目名称上右键-》重新扫描解决方案

    评论
    解决 无用
    打赏 举报