链接器错误:未定义的引用/错误的重新定位地址/ld返回1个出口
Linker Error: Undefined reference / bad reloc address / ld returned 1 exit
我对编程比较陌生,尤其是面向对象语言。我有类播放器,正在尝试在main中使用简单的数学函数进行测试。我注意到链接器错误,但忽略了它们,直到我在函数调用语句中走得更远,现在我有点不知道该在哪里看。我想我误解了重叠的构造函数/构造函数......
这是我的错误:
*C:UsersNytzaAppDataLocalTempccRUivW8.o ootest.cpp:(.text+0x272): undefined reference to `Player::Player(char const*, int, int, int)'
C:UsersNytzaAppDataLocalTempccRUivW8.o ootest.cpp:(.text+0x27e): undefined reference to `Player::Player()'
C:UsersNytzaAppDataLocalTempccRUivW8.o ootest.cpp:(.text+0x2a5): undefined reference to `Player::Player(char const*, int, int, int)'
C:UsersNytzaAppDataLocalTempccRUivW8.o ootest.cpp:(.text+0x2cc): undefined reference to `Player::Player(char const*, int, int, int)'
C:UsersNytzaAppDataLocalTempccRUivW8.o ootest.cpp:(.text+0x2f6): undefined reference to `Player::Player(char const*, int, int, int)'
C:UsersNytzaAppDataLocalTempccRUivW8.o ootest.cpp:(.text+0x320): undefined reference to `Player::Player(char const*, int, int, int)'
c:program files (x86)dev-cppmingw64x86_64-w64-mingw32binld.exe C:UsersNytzaAppDataLocalTempccRUivW8.o: bad reloc address 0x0 in section `.pdata$_ZStanSt13_Ios_FmtflagsS_'
D:DocumentsProgramscollect2.exe [Error] ld returned 1 exit status*
包括/玩家类
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <string.h>
using namespace std;
class Player
{
public:
Player();
Player( const char [], int, int, int );
void printPlayer();
void printPlayer(const char[], int, int, int);
void setName();
void setName( const char [] );
void changeGoals( int );
void changeAssists( int );
void changeRating( int );
int getGoals();
int getAssists();
int getRating();
private:
char name[50];
int goals;
int assists;
int rating;
};
错误在 main 中添加这些行后开始:
int main()
int main()
{
Player p1 ("Nytza Delirosa", 1, 1, 1);
Player p2;
Player p3 ("Jonathan Toews", 10, 9, 6);
Player p4 ("Patrick Kane", 11, 10, -3);
Player p5 ("Brandon Saad", 5, 8, 8);
Player p6 ("Andrew Shaw", 6, 5, 6);
...
return 0;
}
我的所有功能:
void Player::printPlayer()
{
int points = getGoals() + getAssists();
cout << name << endl <<
"Goals: " << goals <<
"Assists: " << assists <<
"Points: " << points <<
"Plus/Minus: " << showpos << rating << noshowpos << endl << endl;
}
void Player::setName()
{
name[0] = ' ';
}
void Player::setName( const char playerName[] )
{
strcpy(name, playerName);
}
void Player::changeGoals( int goalsScored )
{
if (goalsScored < 0 )
cout << "Error: Not at least 0 goals.";
else goals++;
}
void Player::changeAssists( int assistsEarned )
{
if (assistsEarned < 0 )
cout << "Error: Not at least 0 assists.";
else assists=+assistsEarned;
}
int Player::getGoals()
{
return goals;
}
int Player::getAssists()
{
return assists;
}
int Player::getRating()
{
return rating;
}
显然你没有定义Player
的构造函数:
Player();
Player( const char [], int, int, int );
至少添加如下的存根定义:
Player::Player()
{
}
Player::Player( const char [], int, int, int )
{
}
相关文章:
- 为什么我在leetcode上收到AddressSanitizer:地址0x602000000058上的堆缓冲区溢出错误
- 地址的奇怪错误
- 为什么我得到以下代码地址清理器:未知地址错误的SEGV
- 运行时错误:引用绑定到类型"int"的未对齐地址0xbebebebebebebec6,这需要 4 个字节对齐 (stl_vector.h)
- 我有一个线程 1:EXC_BAD_ACCESS(代码 = 1,地址 = 0x8)错误.我认为这是由于内存管理不好.我可以
- Assimp 库错误:获取打包成员的地址
- 运行时错误地址清理器:LEETCODE 中的致命信号
- 瓦尔格林德错误 - 地址0x0不是堆叠的 malloc'd 或自由的
- 获取未知分段错误"(地址)在 std::__cxx11::basic_string<char, std::char_traits<char>,..., std::分配器<cha
- 来自简单循环的 OpenAcc 错误:内核执行期间的非法地址
- 带有 NORM 的 ZeroMQ - 地址已在使用 错误被抛出在第二个 .bind() 上 - 为什么?
- 重载新返回错误的地址
- 线程 1:xcode 中出现EXC_BAD_ACCESS(代码 = 1,地址 = 0x0)错误
- C++带有 CMakeList 的地址清理器.txt会导致 asan 错误
- 为什么这段代码给出错误......'a'是指针到字符指针,应该存储's'的地址,因为s是指向数组的第一个元素的指针
- C++ 临时地址不会导致生成错误
- 为什么 LeetCode 给出错误:地址清理器:堆缓冲区溢出
- 分段错误:地址未映射/地址失败:(无)
- 为什么在递增后使用 [] 运算符访问指针数组会返回错误地址的当前内存位置
- 绑定错误:地址已在使用中