【发布时间】:2020-03-06 04:30:50
【问题描述】:
我有一个简单的学生项目,我需要一些帮助。我收到一条消息,其中包含我无法修复的某种错误。请帮我解决。该项目使用 C++。以下是我的代码:
#include <iostream>
#include <stdlib.h>
#include <list>
#include <set>
using namespace std;
struct V
{
char name;
list <V> to_v;
};
list <V> graph_v;
set <char> PoseteniVarhove;
list <V> ::iterator ukaz(char name)
{
list <V> ::iterator retukaz = (list <V> ::iterator) NULL; // <-- ERROR HERE
for (list <V> ::iterator it = graph_v.begin(); it != graph_v.end(); it++)
if ((*it).name == name)
retukaz = it;
return retukaz;
}
void MakeGraph()
{
int n, br;
V v;
list <V> ::iterator it;
char name;
do
{
cout << "Broy varhove(1..26): "; cin >> n;
} while (n < 1 || n > 26);
graph_v.clear();
for (int c = 0; c < n; c++)
{
v.name = (char)('A' + c);
v.to_v.clear();
graph_v.push_back(v);
}
for (it = graph_v.begin(); it != graph_v.end(); it++)
{
cout << endl;
cout << "Vrah " << (*it).name << endl;
cout << "Kam kolko drugi varha ima nasocheni rebra? ";
cin >> br;
for (int k = 0; k < br; k++)
{
cout << "Rebro kam vrah #" << 1 + k << endl;
cout << "Ime na varha('A'..'Z'): ";
cin >> name;
v.name = name;
v.to_v.clear();
v.to_v.push_back(*ukaz(name));
(*it).to_v.push_back(v);
}
}
}
void PrintGraph()
{
list <V> ::iterator it, it1;
for (it = graph_v.begin(); it != graph_v.end(); it++)
{
cout << endl << "Ot vrah " << (*it).name << " kam varhove ";
for (it1 = (*it).to_v.begin(); it1 != (*it).to_v.end(); it1++)
cout << (*it1).name << " ";
}
cout << endl;
}
bool Path(char beginVrah, char TekVrah, char Target)
{
bool P = false;
list <V> ::iterator uk, it;
if (PoseteniVarhove.count(TekVrah) == 0)
{
uk = ukaz(TekVrah);
PoseteniVarhove.insert(TekVrah);
for (it = (*uk).to_v.begin(); it != (*uk).to_v.end(); it++)
{
if ((*it).name == Target)
return true;
else
if ((*it).name != beginVrah && !P)
P = Path(beginVrah, (*it).name, Target);
}
}
return P;
}
void Paths()
{
int Count = 0;
bool P;
list <V> ::iterator it, it1;
for (it = graph_v.begin(); it != graph_v.end(); it++)
for (it1 = it; it1 != graph_v.end(); it1++)
if (it != it1)
{
P = false;
PoseteniVarhove.clear();
if (Path((*it).name, (*it).name, (*it1).name))
P = true;
PoseteniVarhove.clear();
if (Path((*it1).name, (*it1).name, (*it).name) && P)
{
cout << (*it).name << ' ' << (*it1).name << endl;
Count++;
}
}
cout << "Obshto " << Count << " dvoyki" << endl << endl;
}
int main()
{
char ch[256];
int choice;
cout << "Graph" << endl;
do
{
cout << endl << "1. Vavezhdane na Graph" << endl;
cout << "2. Izvezhdane na Grapha" << endl;
cout << "3. Paths" << endl;
cout << "4. Kray" << endl;
do
{
cout << "(1,2,3,4): ";
cin >> ch;
choice = atoi(ch);
} while (choice < 1 || choice > 4);
switch (choice)
{
case 1:
MakeGraph();
break;
case 2:
PrintGraph();
break;
case 3:
Paths();
break;
case 4:
break;
default:
break;
}
} while (choice < 4);
return 0;
}
出现如下错误:
没有构造函数可以采用源类型,或者构造函数重载决议不明确
MSVC 在函数ukaz 的第一行指向NULL。
【问题讨论】:
-
一个建议:变量名和 cmets 应该支持程序的读者 - 编译器不在乎。我是该程序的读者,我不明白。在制作minimal reproducible example 时,请花时间将变量和纯文本翻译成英文,然后再发布到 SO。这将使更多人能够了解程序中应该发生的事情 - 并可能给出答案。
标签: c++