const .. struct
-
hi erstmal,
also ich habe hier ein kleines Problem.
Ich will mit sockets eine serververbindung machen, in etwa so:struct sockaddr_in {
short int sin_family;
unsigned short int sin_port;
struct in_addr sin_addr;
};
int s;
sockaddr_in addr;
s=socket(AF_INET,SOCK_STREAM,0);
...
c=connect(s, &addr, sizeof(addr));
...
bind(s,&addr,sizeof(addr));
.
.
.für bind und connect bringt er dann den fehler:
type `const sockaddr_in' is not a base type for type `main()::sockaddr_in'freue mic hauf antworten thx mfg
-
versuch mal:
int c = connect (sock, (struct sockaddr *) &addr, sizeof(addr));
-
In C++ werden die Zeiger auf verschiedene structs ('struct sockaddr_in' und 'struct sockaddr' zB) nicht automatisch ineinander umgewandelt. Diese Umwandlung ist aber hier, zulässig und sinnvoll. Du wirst also den Typen explizit umwandeln -- casten -- müssen.
-
wenn du mir noch sagen würdest wie fände ich das sehr nett
-
hast meinen cast versucht?
-
ja kamen nur noch mehr fehler als davor
-
argl ne sry, hab das falsch verstanden...das geht jetzt schon
ich bekomm jetzt nurnoch tonnenweise linkerfehler.
Das liegt doch w*****einlich an der fehlenden wsock32.lib ... wo bekomme ich die her ?
-
was benutzt du für nen compiler? wenn msvcc dann versuchs mal in dem forum. glaube allerdings, dass du bzgl. dazu was in der faq und auch über die suchfunktion kriegst