未定义的引用错误,我该怎么办?
undefined reference error, what should i do?
你好,这是我第一次来这里,我需要帮助,我必须发送一个最终项目,一个"备忘录",但向我展示了这个问题:
main.cpp:(.text+0xa95(: 对'inicio(std::string*, std::string*('的未定义引用
main.cpp:(.text+0x1586(:对"over(("的未定义引用
我不知道为什么,我也说西班牙语,所以代码是英语和西班牙语的混合体,这是代码:请有人帮助我
主.cpp
#include <iostream>
#include <string>
#include <windows.h>
#include <time.h>
#include <unistd.h>
#include "Jugadores.h"
using namespace std;
void inicio (string* j1, string* j2);
void over (void);
int main()
{
string materias[]={"", "Calculo", "Programacion", "Ingles", "Fisica", "Español", "Politica", "Deporte", "Matematicas", "Aula", "Fundamentos", "IPOO", "Algebra"};
string nuevo[24];
nuevo [0]="0";
string posicion[]={"","1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24"};
int ale[24]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int numeroa;
srand (time(NULL));
string auxiliop, auxilios;
int i=1,P,S,j=1,p;
int rep;
int pares=0;
int pj1=0,pj2=0,turn=2;
string d1, d2;
int ocupados[24];
int z=0,r=0, yaesta;
Jugadores jugador1;
Jugadores jugador2;
inicio(&d1, &d2);
jugador1.ingresanombre(d1);
jugador2.ingresanombre(d2);
sleep(1000);
while(i<=24)
{
numeroa=1+rand()%24;
rep=0;
j=1;
while(j<=24)
{
if (numeroa=ale[j])
{
rep=1;
}
j++;
}
if (rep!=1)
{
ale[i]=numeroa;
i++;
}
}
cout<<"nnn";
for (i=1;i<=24;i++)
{
nuevo[i]=materias[ale[i]];
}
cout<<"nn";
i=1;
while(i<=24)
{
cout<<"t" << posicion[i];
if (i==6 || i==12 || i==18 || i==24) cout<<"nnn";
i++;
}
i=1;
while (pares<12)
{
cout << "nn";
if (turn%2==0)
{
cout << "Es turno de: " << jugador1.mostrarnombre();
}
else
{
cout << "Es turno de: " << jugador2.mostrarnombre();
}
cout << "nEscoge 2 numeros mostrados en pantalla: nNumero1: ";
cin >> P;
cout << "nNumero 2: ";
cin >> S;
for (r=0;r<=z;r++)
{
if (ocupados[r]==P||ocupados[r]==S)
{
yaesta=1;
}
}
system ("cls");
rep=1;
while (rep == 1)
{
if (P==S || P<24 || P<1 || S<24 || S<1 || yaesta==1)
{
cout<< "nError al introducir los datosnIngresa unos nuevos:nn";
cout<<"Numero 1: ";
cin >> P;
cout<< "nNumero 2: ";
cin >> S;
system ("cls");
yaesta=0;
}
else rep=2;
if (nuevo[P]==nuevo[S])
{
ocupados[z]=P;
ocupados[z+1]=S;
z+=1;
pares=pares+1;
if (turn%2==0)
{
jugador1.entrapuntuacion(1);
}
else
{
jugador2.entrapuntuacion(1);
}
system ("cls");
cout<< "nntCorrecto!!nn";
posicion[P]=nuevo[P];
posicion[S]=nuevo[S];
i=1;
cout<<"n";
while (i<=24)
{
cout << "t" << posicion [i];
if (i==6||i==12||i==18||i==24) cout<<"nnn";
i++;
}
}
else
{
auxiliop=posicion[P];
auxilios=posicion[S];
posicion[P]=nuevo[P];
posicion[S]=nuevo[S];
i=1;
cout << "n";
while (i <= 24)
{
cout << "t" << posicion[i];
if (i==6||i==12||i==18||i==24) cout << "nnn";
i++;
}
posicion[P]=auxiliop;
posicion[S]=auxilios;
sleep(2000);
system("cls");
turn++;
cout << "nnCambio de jugador!!nnn";
i=1;
while (i<=24)
{
cout<< "t" << posicion[i];
if (i==6||i==12||i==18||i==24) cout<< "nnn";
i++;
}
}
cout<< "n los puntos de " << jugador1.mostrarnombre() << " son " << jugador1.mostrarpuntuacion();
cout<< "n los puntos de " << jugador2.mostrarnombre() << " son " << jugador2.mostrarpuntuacion() << endl;
}
if(jugador1.mostrarpuntuacion() > jugador2.mostrarpuntuacion())
{
cout<<jugador1.mostrarnombre() << "tEs el ganador!!";
}
else if (jugador1.mostrarpuntuacion()==jugador2.mostrarpuntuacion())
{
cout << "nnttTenemos un empate!!";
}
else
{
cout << jugador2.mostrarnombre() << "tEs el ganador!!";
}
sleep(2000);
system("cls");
for (p=0;p<10;p++)
{
sleep(500);
over();
sleep(500);
system("cls");
}
}
void over (void);
{
cout<<"tn••••• ••••• • • ••••• • • •• ••• •••••n";
cout<<"• • • •• •• • • • • • •n";
cout<<"• •• ••••• • • • •••• • • •••• ••••• n";
cout<<"• • • • • • • • • • • • n";
cout<<"••••• • • • • ••••• • ••••• • • n";
}
void inicio (string* j1, string* j2);
{
cout << "Bienvenido";
}
string *j1, *j2;
sleep(1000);
cout << "nnnnttttNombre Jugador 1: ";
cin>> *j1;
cout << "nnttttNombre Jugador 2: ";
cin>> *j2;
system("cls");
cout<<"nnnnnnntttt" << *j1 << "t vs t" << *j2;
sleep(1000);
cout << "nnntt";
system("pause");
system("cls");
}
朱加多尔·
#ifndef JUGADORES_H
#define JUGADORES_H
#include <string>
using namespace std;
class Jugadores
{
private:
int puntos;
string Nombre;
public:
void entrapuntuacion(int);
int mostrarpuntuacion(void);
void ingresanombre(string );
string mostrarnombre(void);
};
#endif
朱加多尔.cpp
#include "Jugadores.h"
#include <string>
#include <windows.h>
#include <time.h>
using namespace std;
void Jugadores::entrapuntuacion(int P)
{
if (P==1)
{
puntos++;
}
}
int Jugadores::mostrarpuntuacion()
{
return(puntos);
}
void Jugadores::ingresanombre(string N)
{
Nombre=N;
}
string Jugadores::mostrarnombre(void)
{
return(Nombre);
}
<string.h>
是- 来自
C
语言的标头,用于处理const char*
字符串。 <string>
是来自C++
语言的标头,用于处理std::string
字符串。
因此,只需从#include
行中删除该.h
即可。
一般来说,任何C
标头都会有.h
,但任何C++
标头都不会。请注意,C
标头有C++
版本,它们会稍微更改名称。例如,C
中的<stdio.h>
在"C++"中变为<cstdio>
。
因此,在您的代码中,您可能还想更改<ctime>
的<time.h>
。
但这不适用于<unistd.h>
,因为这是一个POSIX标准库,而不是一个C
标准库。
是的,这令人困惑...
>C++不允许在另一个函数中定义一个函数。你把它隐藏得很好,我不得不多次阅读代码才能理解发生了什么。
文件顶部正确:
using namespace std;
void inicio (string* j1, string* j2);
void over (void);
int main()
{
...
这将inicio
和over
声明为函数并定义main
。
让我们看一下函数的定义
void over (void);
{
cout<<"tn n";
cout<<" n";
cout<<" n";
cout<<" n";
cout<<" n";
}
void inicio (string* j1, string* j2);
{
cout << "Bienvenido";
}
string *j1, *j2;
sleep(1000);
cout << "nnnnttttNombre Jugador 1: ";
这发生在 main 的定义中。由于void over(void);
末尾的分号(;
(和void inicio (string* j1, string* j2);
这些行只是函数的声明。接下来只是编译为main的一部分的指令块。
应该做什么:简单地定义main 结束后的函数:
...
cout << "nnntt";
system("pause");
system("cls");
}
void over (void) // note the suppression of ;
{
cout<<"tn n";
cout<<" n";
cout<<" n";
cout<<" n";
cout<<" n";
}
void inicio (string* j1, string* j2)
{
cout << "Bienvenido";
}
相关文章:
- 我的 cout 上有一个奇怪的输出,它把答案放在第一位,然后在我调用它的地方放一个奇怪的输出.我该怎么办?
- 当两个相等的双精度的相对比较不起作用时,我该怎么办?
- 我需要通过窗口句柄(HWND)获取文件,我该怎么办?
- 我正在"void value not ignored as it ought to be"我该怎么办?
- 未定义的引用错误,我该怎么办?
- 我在此代码中要求一个数字,如果用户给出一个字母,我该怎么办?
- 当一个功能完成另一个功能打开时,我该怎么办?
- 如果我尝试将 graphics.h 用于 c/c++ 时显示错误,我该怎么办?
- 这对我来说真的很难,我该怎么办
- 在C 中,我该怎么办才能格式化输出
- 当MPI中未知的发送消息数量时,我该怎么办
- 如果违反了利斯科夫替代原则,我该怎么办?
- 当(CUDA 7.5的)nvcc / cudafe++崩溃并出现段错误时,我该怎么办?
- 当来自外部库的线程不可预测地崩溃我的应用程序时,我该怎么办
- C++ 中的整数范围 - 当标准尚不存在时我该怎么办
- Visual Studio C++:获取未解析的令牌和未解析的链接.我该怎么办
- qextserialport在Windows上丢弃数据——我该怎么办
- 函数内存不足-我该怎么办
- 此代码显示错误"stu undeclared" ??我该怎么办
- 错误:没有匹配' operator == ',我该怎么办?