typedefvoid(*mything)(int a);
struct MyStruct
{
mything mythingTwo;
}
void MyThingBig()
{
MyStruct tempstruct; //Declare a temporary struct to set values.
tempstruct.mythingTwo = NULL; //Set it equal to some value. I just set this pointer to null.
return tempstruct;
//something
}
int main()
{
/*In order to declare a variable of the struct type you have above, you will need to
use the struct name as the datatype,
then the name of the variable you want to declare.
*/
MyStruct some;
/* To call the function don't forget the parenthesis!
Also, you don't need to reference the
variable in your struct (some.mythingTwo)
if you're using a function to set the values (which I assumed you were doing).
Just return the temporary struct to the caller.
*/
some = MyThingBig();
}
I hope that helped. I kind of assumed what you were trying to get at.
1 2 3 4 5 6
int** apointer;
/*This has two asterisks because it is a pointer(a variable that holds a memory address) that points to another pointer.
You can have even more than that the farther you go.
If you have a pointer that points to a pointer that points to a pointer, you can get something that looks like int*** apointer;
These are used more when you get into dynamically allocated multidimensional arrays.
*/
Also, I don't think you can compare strings like that. I think you need to use strcmp(); Technically a string is an array of characters. So you're comparing a string literal to a pointer.
I saw people doing what i said.
Like in libircclient
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
typedefstruct
{
irc_event_callback_t event_connect;
irc_event_callback_t event_nick;
irc_event_callback_t event_quit;
//ecc
}
//and then addin to a value a funcion, withouth the parenthesis like this:
void myfunction(values value, values2 value, more ecc)
{
//Lalala
}
irc_callbacks_t something;
something.event_connect = myfunction;
What's the point of typedef void(*mything)(int a);
Also, I don't think you can compare strings like that
std::string can be compared with c-string directly.
What would be the best metod?
Whichever is clearer.
either yours or std::strcmp(argv[1]. "Hello");
But i think that is a waste of space, since declaring a new variable.
Premature optimization. Unless you on some embedded system with 32k of memory you should not worry about it. Also you can wrap it in separate block to make it auto-destruct.
typedefvoid(*mything)(int a);This code declares type alias mything as pointer to function taking integer and returning void. Is used because it is way better to write
typedefstruct
{
irc_event_callback_t event_connect;
irc_event_callback_t event_nick;
irc_event_callback_t event_quit;
//ecc
}
//and then addin to a value a funcion, withouth the parenthesis like this:
void myfunction(values value, values2 value, more ecc)
{
//Lalala
}
irc_callbacks_t something;
something.event_connect = myfunction; //here
You do not need parentesis because you do not calling function. You are assigning it address to something.event_connect pointer which you can use to call tat function later.
Example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
void foo()
{
std::cout << "foo\n";
}
void bar()
{
std::cout << "bar\n";
}
int main()
{
using fptr = void(*)();
fptr x = foo;
x(); //Prints "foo"
x = bar;
x(); // prints "bar"
}