nixp.ru v3.0

29 марта 2024,
пятница,
10:25:45 MSK

Аватар пользователя unkier
unkier написал 15 апреля 2007 года в 21:20 (931 просмотр) Ведет себя неопределенно; открыл 12 тем в форуме, оставил 22 комментария на сайте.

есть класс (tcp сокет), у него метод open (задание носта и порта куда коннектится)

прототипы:

void open(const std::string& address, int service, bool nonblock = false);

void open(const std::string& address, int service, unsigned int milliseconds);

при попытке позвать его внутри метода моего класса

CommClient::CommClient(const std::string& host, int port)

{

m_clientSocket.open(host,port,10);

компилер ругается

g++ -O3 -Wall -osrc/CommClient.o ../src/CommClient.cpp

../src/CommClient.cpp: In constructor `CommClient::CommClient(const std::string&, int)’:

../src/CommClient.cpp:6: error: call of overloaded `open(const std::basic_string, std::allocator >&, int&, int)' is ambiguous

skstream.h:299: note: candidates are: void tcp_socket_stream::open(const std::string&, int, bool)

skstream.h:300: note: void tcp_socket_stream::open(const std::string&, int, unsigned int)

если захардкодить параметры:

m_clientSocket.open(«somehost.com»,21,10);

то пишет

g++ -O3 -Wall -osrc/CommClient.o ../src/CommClient.cpp

../src/CommClient.cpp: In constructor `CommClient::CommClient(const std::string&, int)’:

../src/CommClient.cpp:5: error: call of overloaded `open(const char[13], int, int)' is ambiguous

skstream.h:299: note: candidates are: void tcp_socket_stream::open(const std::string&, int, bool)

skstream.h:300: note: void tcp_socket_stream::open(const std::string&, int, unsigned int)

буквально парой строчек ниже есть вызов метода у которого параметр тоже const

std::string & и никаких проблем

gcc 3.4.2

как такое может быть ???

metal

Внимательно смотришь на 3-й параметр и представляешь себя компилятором. Как ему догадаться что делать с int?

unkier

точно, дело в этом

спасибо

я почемуто считал что компилер int к unsigned int в состоянии привести…

и меня смущала его ругань на первый параметр

Code Monkey

Сокеты? Юникс? Стивенс!

Последние комментарии

ecobeingecobeing.ru
Экология и вегетарианство на благо всем живым существам Планеты.