"Undefined symbols for Architecture x86_64 "未使用模板,可能存在语法错误
"Undefined symbols for Architecture x86_64 " no templates used, possible syntax error
我知道这是一个常见的问题,但请耐心等待。根据我对过去问题的理解:
- 我没有使用模板,所以在每次使用模板之前都会使用类似于"模板类TreeNode;"的东西,但我认为问题是类似的,与语法有关的,或者是非常基本的。如果我得到了答案,我会编辑这个问题,让更多的人从中受益
所以我所要做的就是使用这些代码在main.cpp中进行一些操作来执行一些操作,例如使用DeleteItem、Retrieve 10和打印是否找到等。
代码如下:
//unsortedtype.h
#ifndef UNSORTEDTYPE_H_INCLUDED
#define UNSORTEDTYPE_H_INCLUDED
#include "itemtype.h"
class UnsortedType
{
public:
UnsortedType();
bool IsFull() const;
int LengthIs() const;
void RetrieveItem(ItemType&item, bool&found);
void InsertItem(ItemType item);
void DeleteItem(ItemType item);
void ResetList();
void GetNextItem(ItemType& item);
void PrintList();
private:
int length;
ItemType info[MAX_ITEMS];
int currentPos;
};
#endif // UNSORTEDTYPE_H_INCLUDED
//fileno2
//unsortedtyoe.cpp
#ifndef UNSORTEDTYPE_CPP_INCLUDED
#define UNSORTEDTYPE_CPP_INCLUDED
#include "unsortedtype.h"
UnsortedType::UnsortedType()
{
length = 0;
currentPos = -1;
}
bool UnsortedType::IsFull() const
{
return (length == MAX_ITEMS);
}
int UnsortedType::LengthIs() const
{
return length;
}
void UnsortedType::RetrieveItem(ItemType &item, bool &found){
int location = 0;
bool moreToSearch = (location < length);
found = false;
while (moreToSearch && !found){
switch (item.ComparedTo(info[location]))
{
case LESS:
case GREATER:
location++;
moreToSearch = (location < length);
break;
case EQUAL:
found = true;
}
}
}
void UnsortedType::InsertItem(ItemType item)
{
info[length] = item;
length++;
}
void UnsortedType::DeleteItem(ItemType item){
int location = 0;
while (item.ComparedTo(info[location]) != EQUAL){
location++;
info[location] = info[length - 1];
length++;
}
}
void UnsortedType::ResetList(){
currentPos = -1;
}
void UnsortedType::GetNextItem(ItemType &item){
currentPos++;
item = info[currentPos];
}
void UnsortedType::PrintList(){
ItemType it;
for (int i = 1; i <= length; i++){
GetNextItem(it);
it.Print();
cout<<"";
}
ResetList();
cout<<endl;
}
#endif // UNSORTEDTYPE_CPP_INCLUDED
//fileno3
//itemtype.h
#ifndef ITEMTYPE_H_INCLUDED
#define ITEMTYPE_H_INCLUDED
#include <iostream>
using namespace std;
const int MAX_ITEMS = 5;
enum RelationType{LESS, GREATER, EQUAL};
class ItemType{
public:
ItemType();
RelationType ComparedTo(ItemType) const;
void Print() const;
void Initialize(int number);
private:
int value;
} ;
#endif // ITEMTYPE_H_INCLUDED
fileno4
//itemtype.cpp
#ifndef ITEMTYPE_CPP
#define ITEMTYPE_CPP
#include "itemtype.h"
ItemType::ItemType(){
value = 0;
}
RelationType ItemType::ComparedTo(ItemType otheritem) const
{
if (value<otheritem.value)
return LESS;
else if (value > otherItem.value)
return GREATER;
else
return EQUAL;
}
void ItemType::Initialize(int number){
value = number;
}
void ItemType::Print() const
{
cout << value << "";
}
#endif // ITEMTYPE_CPP
主
#include <iostream>
#include "itemtype.h"
#include "unsortedtype.h"
using namespace std;
int main()
{
UnsortedType ustype1;
cout << ustype1.LengthIs() << endl;
/*
//insertItem
ustype1.InsertItem(5);
ustype1.InsertItem(7);
ustype1.InsertItem(6);
ustype1.InsertItem(9);
ustype1.PrintList();
ustype1.InsertItem(1);
ustype1.PrintList();
//RetreiveItem
bool found;
ustype1.RetrieveItem(4, found);
cout << found << endl;
ustype1.RetrieveItem(5, found);
cout << found << endl;
ustype1.RetrieveItem(9, found);
cout << found << endl;
ustype1.RetrieveItem(10, found);
cout << found << endl;
//isFULL
cout << ustype1.IsFull() << endl;
ustype1.DeleteItem(5);
cout << ustype1.IsFull() << endl;
//deleteItem
ustype1.DeleteItem(1);
ustype1.PrintList();
ustype1.DeleteItem(6);
ustype1.PrintList();
*/
cout << "Hello world!" << endl;
return 0;
}
我的第一个问题是,当我去掉main中的注释行,只做IsLength时,我会得到:https://i.stack.imgur.com/49JMw.png
我认为这可能是一个非常基本的错误,如果你能告诉我如何解决这个问题,我将非常感激。
PPS>可能有点懒,但当我在Main中使用注释掉的代码时,我收到了这个错误,有人能快速告诉我如何将整数作为ItemType插入到这些函数中吗?
https://i.stack.imgur.com/JOhia.png
编辑:图像1:
-------------- Build: Debug in UnsortedList (compiler: GNU GCC Compiler)---------------
g++ -o bin/Debug/UnsortedList obj/Debug/main.o obj/Debug/unsortedtype.o -lstdc++
Undefined symbols for architecture x86_64:
"ItemType::ItemType()", referenced from:
UnsortedType::UnsortedType()in unsortedtype.o
UnsortedType::UnsortedType()in unsortedtype.o
UnsortedType::PrintList() in unsortedtype.o
"ItemType::ComparedTo(ItemType) const", referenced from:
UnsortedType::DeleteItem(ItemType) in unsortedtype.o
UnsortedType::RetrieveItem(ItemType&, bool&) in unsortedtype.o
"ItemType::Print() const", referenced from:
UnsortedType::PrintList() in unsortedtype.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minute(s), 0 second(s))
0 error(s), 0 warning(s) (0 minute(s), 0 second(s))
您应该在命令行上指定itemtype.o,如下所示。
g++-o bin/Debug/UnsortedList obj/Debug/main.o obj/Debug/unsortedtype.obj/Debug/itemtype.o
编译main()
时未指定itemtype.o
g++ -o bin/Debug/UnsortedList obj/Debug/main.o obj/Debug/unsortedtype.o obj/Debug/itemtype.o
相关文章:
- 为什么包含windows.h会产生语法错误,从而阻止类的实例化?(C2146,C2065)
- 错误 C2760:语法错误:映射迭代器上意外的标记"标识符",预期的";"
- 为什么我会收到错误 C2143 语法错误:缺少"*"之前的';'?
- 奇怪的代码抛出编译错误模板< J,int aSize=10> C2143:语法错误:在"<"之前缺少";"
- "错误 C0000:语法错误,令牌"<EOF>"处出现意外$end,并且不确定
- 我该怎么做才能摆脱使用命名空间时的语法错误?
- C++语法头文件错误
- 如何摆脱错误c2061;语法错误 cout?
- 语法错误:D3DX10Core 中的标识符'TEXTMETRICA'
- 错误 C2146:语法错误:标识符"A1"之前缺少","
- main.cpp(11):错误 C2059:语法错误:"字符串"
- 我想获取点的属性,它报告错误 C3867:"point::output_x":非标准语法;使用"&"创建指向成员的指针
- RedisGraph 语法错误在偏移量 8 靠近"创建"
- 如何修复此 FSM C++语法错误 C3867
- 函数错误 C2059:语法错误:'>'不起作用
- 为什么在main()之前断言会导致语法错误"error: expected ')' before numeric constant"?
- system() 返回错误语法错误:"("意外
- C++图形初始化错误(语法或丢失文件缺陷?
- 获取0:1(1):错误:语法错误,尝试编译着色器时意外$end
- Visual Studio错误:语法错误:标识符