编译器中发生内部错误。

shelleyHLX 2015-10-04 08:37:57
f:\vs2013documents\visual c++2013入门经典\visual c++2013入门经典\person.h(35): fatal error C1001: 编译器中发生内部错误。
1> (编译器文件“msc1.cpp”,第 1325 行)
1> 要解决此问题,请尝试简化或更改上面所列位置附近的程序。
1> 请选择 Visual C++
1> “帮助”菜单上的“技术支持”命令,或打开技术支持帮助文件来获得详细信息。
========== 生成: 成功 0 个,失败 1 个,最新 0 个,跳过 0 个 ==========

头文件:
// Person.h
// A class defining a person
#pragma once
#include <iostream>
#include <string>

class Person
{
public:
Person(const std::string first, const std::string second) :
firstname{ std::move(first) }, secondname{ std::move(second) } {}

Person() = default;

// Less-than operator
bool operator<(const Person& p)const
{
return (secondname < p.secondname ||
((secondname == p.secondname) && (firstname < p.firstname)));
}

// Greater-than operator
bool operator>(const Person& p)const
{
return p < *this;
}

// Output a person
void showPerson() const
{
std::cout << firstname << " " << secondname << std::endl;
}

private:
std::string firstname{};
std::string secondname{};
};


源文件:
// Ex10_09.cpp
// Exercising a priority queue container
#include <vector>
#include <queue>
#include <functional>
#include "Person.h"

int main()
{
std::priority_queue<Person, std::vector<Person>, std::greater<> > people;
std::string first, second;
while (true)
{
std::cout << "Enter a first name or press Enter to end: ";
std::getline(std::cin, first);
if (first.empty())
break;

std::cout << "Enter a second name: ";
std::getline(std::cin, second);
people.push(Person{ first, second });
}

std::cout << "\nThere are " << people.size() << " people in the queue." << std::endl;

std::cout << "\nThe names that you entered are:" << std::endl;
while (!people.empty())
{
people.top().showPerson();
people.pop();
}
}
各位高手怎么解决?
...全文
4183 8 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
引用 7 楼 宁可十年不将军,不可一日不拱卒 的回复:
参考:

VS2013使用boost库发生fatal error C1001错误的解决办法

我也是在使用boost库的时候碰到这个异常 正在更新update5,希望有用
clever101 2018-11-17
  • 打赏
  • 举报
回复
安装msvc2013(update 5, 18.00.40629)能解决这个问题吗?
fefe82 2015-10-05
  • 打赏
  • 举报
回复
引用 2 楼 qq_30665499 的回复:
楼主前辈,我是个新手,看到你写的代码想问一句,为啥好多人都不用using nanespace std, 而喜欢写std::呢,不嫌麻烦吗?
using namespace std; 会把所有 std 里的符号引入到全句名字空间,而你并不会知道 std 里都有啥。std 不只会包含标准规定好的名字,同时标准规定好的名字也相当的多。 名字空间的意义就在与避免不同部分的名字之间的冲突(或者称污染),一句 using namespace ,所有的努力都白费了。
shelleyHLX 2015-10-05
  • 打赏
  • 举报
回复
我把头文件的两个{} 去掉就好了 谢谢大家啦! 头文件: // Person.h // A class defining a person #pragma once #include <iostream> #include <string> using namespace std; class Person { public: Person(const string first, const string second) : // firstname{ move(first) }, secondname{ move(second) } {} firstname(std::move(first)), secondname(std::move(second)) {} Person() = default; // Less-than operator bool operator<(const Person& p)const { return (secondname < p.secondname || ((secondname == p.secondname) && (firstname < p.firstname))); } // Greater-than operator bool operator>(const Person& p)const { return p < *this; } // Output a person void showPerson() const { cout << firstname << " " << secondname << endl; } private: string firstname; string secondname; };
shelleyHLX 2015-10-05
  • 打赏
  • 举报
回复
代码换了也不行啊, 源文件: // Ex10_09.cpp // Exercising a priority queue container #include <vector> #include <queue> #include <functional> #include "Person.h" using namespace std; int main() { priority_queue<Person, vector<Person>, greater<> > people; string first, second; while (true) { cout << "Enter a first name or press Enter to end: "; getline(cin, first); if (first.empty()) break; cout << "Enter a second name: "; getline(cin, second); people.push(Person{first, second}); } cout << "\nThere are " << people.size() << " people in the queue." << endl; cout << "\nThe names that you entered are:" << endl; while (!people.empty()) { people.top().showPerson(); people.pop(); } } 头文件: // Person.h // A class defining a person #pragma once #include <iostream> #include <string> using namespace std; class Person { public: Person(const string first, const string second) : // firstname{ move(first) }, secondname{ move(second) } {} firstname(std::move(first)), secondname(std::move(second)) {} Person() = default; // Less-than operator bool operator<(const Person& p)const { return (secondname < p.secondname || ((secondname == p.secondname) && (firstname < p.firstname))); } // Greater-than operator bool operator>(const Person& p)const { return p < *this; } // Output a person void showPerson() const { cout << firstname << " " << secondname << endl; } private: string firstname{}; string secondname{}; };
qq_30665499 2015-10-05
  • 打赏
  • 举报
回复
楼主前辈,我是个新手,看到你写的代码想问一句,为啥好多人都不用using nanespace std, 而喜欢写std::呢,不嫌麻烦吗?
iyomumx 2015-10-04
  • 打赏
  • 举报
回复
更新一下你的编译器,有条件就装2015。 如果是最新的msvc2013(update 5, 18.00.40629),把头文件的第11行改为
firstname( std::move(first) ), secondname( std::move(second) ) {}
这是编译器bug

65,186

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧