|
The next sample for Visual Studio 2005 uses map and function pointers:
#include "stdafx.h"
#include "math.h"
#include <map>
#include <string>
void main()
{
using namespace std;
typedef double (* FUNCTION_POINTER)(double);
map< string, FUNCTION_POINTER > functions;
functions["sin"] = sin;
functions["cos"] = cos;
functions["tg"] = tan;
std::string name;
name = "cos";
FUNCTION_POINTER function = functions[name];
double result = function(1.2);
}
I hope it works and gives you some ideas.
|
|
|
|
|
a piece of cake, function pointer or functors can do this.
boost
|
|
|
|
|
Complementing to the other answers already given, the quick answer would be no, at least not in the way BASIC (for example) lets you do it (something like execute("a=myfunc(10,20)").
The process of calling functions based on the contents of a string has to be manually coded in some way. The most "automatic" way is the already mentioned "GetProcAddress" (you can hide most of the steps required inside macros or in a general purpose function), but prototypes will be always a pain (unless if they are, trivially, the same).
Depending on the extent of work you are willing to do, you can go as far as building your own C/C++ interpreter. I did this once, for a home automation system, where I made a program to go through all of my header files, scan function names and prototypes, and write code to execute the correct function with the correct parameters based on the contents of a string (the command entered by the user). Is not very hard work if you control the classes and functions. If not then be prepared for trouble.
I hope this helps,
Rilhas
|
|
|
|
|
I have a question.
Are these same?
1. Close the client application window. [ Closes the stream ],
(Server gets out of the below block)
<br />
do<br />
{<br />
n=recv(client,buff,MAX_BUFF_SIZE,0);<br />
if(n==SOCKET_ERROR ) <br />
{<br />
break;<br />
}<br />
}while()<br />
2. UnPlug the client's network cable. [should close the stream?] ,
server never gets notified? it never happens. WTF???
I'm not able to detect the latter one. Please help. If the n/w cable is unplugged, the stream would be broken and it should fire a sock exception right?
<marquee scrollamount="1" scrolldelay="1" direction="up" height="10" step="1">--[ ]--
[My Current Status]
Link2006 wrote:Let's take it outside of CP
Jeremy : Please don't.I would love to see this.I'm making the popcorn already.
|
|
|
|
|
Hi,
the value from SOCKET_ERROR is -1
if you unplug the network recv will be return 0
Change your code to
<br />
do<br />
{<br />
n=recv(client,buff,MAX_BUFF_SIZE,0);<br />
if(1 > n)<br />
{<br />
break;<br />
}<br />
}while();<br />
HTH
Frank
|
|
|
|
|
Nope! It doesn't work. The disconnection is not detected. Please help.
<marquee scrollamount="1" scrolldelay="1" direction="up" height="10" step="1">--[ ]--
[My Current Status]
Link2006 wrote:Let's take it outside of CP
Jeremy : Please don't.I would love to see this.I'm making the popcorn already.
|
|
|
|
|
TCP does _not_ maintain a connection, it only maintains information about the connection.
Unplugging the cable merely prevents data from moving.
You need to implement a ping or timeout type feature in your protocol if you want to be notified if/when the cable is unplugged.
See:
http://tangentsoft.net/wskfaq/newbie.html#abnormalclose[^]
...cmk
Save the whales - collect the whole set
|
|
|
|
|
Thanks for the link!! I just stopped tussling with the issue. Implementing a sensor now
<marquee scrollamount="1" scrolldelay="1" direction="up" height="10" step="1">--[ ]--
[My Current Status]
Link2006 wrote:Let's take it outside of CP
Jeremy : Please don't.I would love to see this.I'm making the popcorn already.
|
|
|
|
|
Hi all,
I'm struggling with the following:
I have these two pointer:
<code>char* username = "value1";
char* servername = "value2";</code>
And these other two pointers:
<code>
unsigned short* uni_domain;
unsigned short* uni_username;
</code>
And I'm trying to assign the fisrt two pointer values to the second two pointer, I tried the following:
<code>
uni_domain = (LPWSTR)username;
uni_username = (LPWSTR)servername;
</code>
But the function : <code>NetUserGetInfo</code> is not equal to <code>NERR_Success</code>, which indicates its not valid.
When I do this it works:
<code>
uni_domain = L"value1";
uni_username = L"value2";
</code>
But I'm sending values to a function, and the above will not help my cause.
Can anyone help me?
Only programmers that are better than C programmers are those who code in 1's and 0's.....
Programm3r
|
|
|
|
|
You can't typcast a unicode string to an ansi string, you must use the MultiByteToWideChar() function, or the W2A macro. I think you would be better off reading about the TCHAR strings and the _T() macro, it's a lot easier to deal with.
|
|
|
|
|
hi everyone,
i have to know that the given CString variable contains numeric value , eg
CString str = "1233.23" , is having a numeric value, i want to trap that.
but problem is that i dont know how to determine that the string variable contain the numeric value. ( not like str ="123hh" or str ="hh1234")
Can any body help me
|
|
|
|
|
iterate through each character. it must contain only 0~9 , + , - , .
|
|
|
|
|
If your strings will always start with a numeric value you can use the atoi() function, but from your example I guess not. You would have to go through each character and text the value.
|
|
|
|
|
How to get your string?from a editbox...?its for only number or string?
|
|
|
|
|
Use isdigit() .
"Talent without discipline is like an octopus on roller skates. There's plenty of movement, but you never know if it's going to be forward, backwards, or sideways." - H. Jackson Brown, Jr.
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
-3.2 is a valid numeric number ; BTW, - and . characters won't be validate by isdigit() though
|
|
|
|
|
True. Those two characters would need to be handled individually. However, a string such as "3.2-" would not be considered a valid number even though it has only . (dot), - (dash), and digits. sscanf() could be used, depending on the tolerances.
"Talent without discipline is like an octopus on roller skates. There's plenty of movement, but you never know if it's going to be forward, backwards, or sideways." - H. Jackson Brown, Jr.
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
You can use the isalpha(int c) to verify each character or you string. If any call to this function returns 1, your string is not composed only by numbers.
|
|
|
|
|
isalpha('}'); will return false, however, the string is not composed only by numbers...
your method has serious lacks
|
|
|
|
|
I just want to practice class using, but met this problem:
fatal error C1004: unexpected end of file found.Could anyone lend me a help,thank you!
Code:
// prac.cpp : Defines the entry point for the console application.
#include "stdafx.h"
#include "iostream"
using namespace std;
class polygon{
protected: int width, height;
public: polygon(int,int);
virtual int area ()
{ return (0); }
};
polygon::polygon(int a,int b)
{
width=a;
height=b;
}
class triangle: public polygon{
public: int area(){
return(width * height/2);
};
class quadrangle:public polygon{
public: int area()
{return (width * height);}
};
void main(int argc, char* argv[])
{
quadrangle ax(10,5);
triangle bx(10,5);
cout << "ax area: " << ax.area() << endl;
cout << "bx area: " << bx.area() << endl;
}
|
|
|
|
|
this is unmanaged C++ ask the correct forum.
|
|
|
|
|
sorry, what does that mean? how to solve it?
|
|
|
|
|
|
toxcct wrote: ask the correct forum[^]...
Hey Tox,
The thread has been moved to the unmanaged C++ forum.
|
|
|
|
|
it wasn't when i wrote it
but yup, you're right
|
|
|
|