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");
}
答
能运行就可以,有时候ide在解析符号,还没有解析完整,于是会有报错提示的误报。关键能编译就说明是对的
答
如果有遇到代码没错误,但是有红色下划线,可以在项目名称上右键-》重新扫描解决方案