gpt4 book ai didi

c++ - 搜索 vector [ 错误包括版本和原始代码 & Makefile ]

转载 作者:太空宇宙 更新时间:2023-11-04 12:20:48 24 4
gpt4 key购买 nike

  • 它给出了这么多错误,为什么?
  • 我该如何解决?

我的真实代码;

 int  SearchUserName (  string searched,   vector<User *> list  )   {
vector<User *> :: iterator it ;
for ( it = list.begin() ; it < list.end ( ) ; ++it ) {
const string tmp = (*it) -> getUsername() ;
if ( tmp == searched ) return 1 ;
}
return 0 ;
}
// SocialNet :: createUser
void SocialNet :: createUser (const string username, const string name, \
const string surname) throw ( SocialNetException ) {
int tmp = SearchUserName ( username, this -> users ) ;
if( tmp == 0) {
User *tmp = NULL ;
tmp = new User( username, name, surname ) ;
users.push_back ( tmp ) ;
return ;
}
throw SocialNetException (USER_ALREADY_EXISTS, username) ;
}

最后,我找到了,错误:

(.text+0x20):对 main' 的 undefined reference
/tmp/cckzaRBZ.o: 在函数中
SearchUserName(std::basic_string, std::allocator >, std::vector >)':SocialNet.cpp:(.text+0x47): 未定义对 User::getUsername() const 的引用
/tmp/cckzaRBZ.o: 在函数中
SocialNet::createUser(std::basic_string, std::allocator >, std::basic_string, std::allocator >, std::basic_string, std::allocator > )':SocialNet.cpp:(.text+0x258): 未定义对`User::User(std::basic_string, std::allocator >, std::basic_string, std::allocator >, std::basic_string, std::分配器 >)'

编辑:在生成文件中;

 CXX = g++
CXXFLAGS_W = -Werror -Wunused-variable -Wunused-value -Wunused-function \
-Wfloat-equal -Wall
CXXFLAGS_M = -ansi -pedantic-errors
CXXFLAGS = ${CXXFLAGS_M} ${CXFLAGS_W}

all: main
./main

编译;制作文件名

最佳答案

您只编译了一个文件。

有点像

main: foo.o bar.o
$(CXX) -o $@ foo.o bar.o

列出你所有的目标文件

关于c++ - 搜索 vector [ 错误包括版本和原始代码 & Makefile ],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5204424/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com