By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,406 Members | 1,055 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,406 IT Pros & Developers. It's quick & easy.

Confusing Typedef/Struct, What Does This Do?

P: n/a
Sorry if this is really dumb, but I've searched for an example like
this and although can find many structures containing references back
to themselves, none with the additional complexities I see here.

I would really appreciate an explanation of what this is / is doing!
Thanks!

typedef struct SocketError {
int socketErrno;
unsigned short socketPort;
const char *message;
SocketError(const int n, const unsigned short q, const char *a)
{socketErrno = n; socketPort = q; message = a;}
};

And is used thusly:

try {
mySnmp = new SnmpSet(mib, sizeof(mib)/sizeof(MIB_T),
strSnmpHost, strSnmpPort, iSnmpInterval);
}
catch (SocketError *e)
{
cout << "Error connecting to SNMP" << endl;
cout << "errno = " << e->socketErrno << ", Port: " <<
e->socketPort;
cout << ", Message: " << e->message << endl;
return false;
}

Obviously I can sort of see what's going on, but an explanation,
specifically of what the "SocketError(param, param, param) {statement;
statement; statement;}" part is doing within the context of the
structure would really help!

Thanks in advance!

Jul 23 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a

j6***************@sneakemail.com wrote:

typedef struct SocketError {
int socketErrno;
unsigned short socketPort;
const char *message;
SocketError(const int n, const unsigned short q, const char *a)
{socketErrno = n; socketPort = q; message = a;}
};
Obviously I can sort of see what's going on, but an explanation,
specifically of what the "SocketError(param, param, param) {statement; statement; statement;}" part is doing within the context of the
structure would really help!

Thanks in advance!


It is a constructor. Just as if SocketError was a class not a struct.
A struct is just a class where all members default to public instead of
private.

The typedef is just a C leftover. Not really needed.
Actually, the typedef is weird - there kinda needs to be a type defined
at the end of the struct, like this:

typedef struct Foo { int x; } Foobar;

ie Foobar is a typedef of struct Foo.

Jul 23 '05 #2

P: n/a
Thank you, that helps!!

Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.