Hello
Got me a little problem with a class that I'm using (or will hopefully use) to control socket/thread flow. For a reason which I cannot guess at, the function Sockets::SwSocks() isn't executing when I put it in my program.
I know to enclose the class function call within its own local brackets, like this
switch (sockState)
case 1:
// code goes here
break;
case 0:
// other code goes here
{Sockets SwSocks; }
break;
default:
std::cout << "Socket error!" << endl;
WSACleanup();
return(SOCKET_FAIL);
but it doesn't work. If I include cout << "##" 's for purposes of debugging, they only show directly before and after the Sockets SwSocks; call.
class Sockets
{
public:
Sockets(){};
Sockets(int){};
virtual void SwSocks();
int Trap();
~Sockets(){};
};
void Sockets::SwSocks()
{
//code to clean up previous work goes here
std::cout << "Sockets switching." << endl;
}
nothing in between like that "Sockets switching" message.
Am I doing something wrong?
Comments
:
: Got me a little problem with a class that I'm using (or will hopefully use) to control socket/thread flow. For a reason which I cannot guess at, the function Sockets::SwSocks() isn't executing when I put it in my program.
:
: I know to enclose the class function call within its own local brackets, like this
:
: switch (sockState)
: case 1:
: // code goes here
: break;
: case 0:
: // other code goes here
: {Sockets SwSocks; }
: break;
: default:
: std::cout << "Socket error!" << endl;
: WSACleanup();
: return(SOCKET_FAIL);
:
: but it doesn't work. If I include cout << "##" 's for purposes of debugging, they only show directly before and after the Sockets SwSocks; call.
:
: class Sockets
: {
: public:
: Sockets(){};
: Sockets(int){};
: virtual void SwSocks();
: int Trap();
: ~Sockets(){};
: };
:
: void Sockets::SwSocks()
: {
: //code to clean up previous work goes here
: std::cout << "Sockets switching." << endl;
: }
:
: nothing in between like that "Sockets switching" message.
:
: Am I doing something wrong?
:
yes, you need to instantiate Sockets ie Sockets sock, then call SwSocks ie sock.SwSocks();
Be wary of scoping issues, creating an object in a inner block, might cause so problems for you.
[italic][blue]Just my 2 bits[/blue][italic]
:
: Be wary of scoping issues, creating an object in a inner block, might cause so problems for you.
Did that ... working now. Thanks.