Hi,
I need implement a map of member functions of some class.
This map is formed by a string and a pointer to the member function.
The problem is that the map need that the object saved are the same
type.
So what type to specify in the declaration of the map?
map<std::string,void *¿?
PD: excuse me for my bad english 11 1805
Manuel wrote:
I need implement a map of member functions of some class.
This map is formed by a string and a pointer to the member function.
Member of what class? What arguments does it take? What type does
it return?
The problem is that the map need that the object saved are the same
type.
Right.
So what type to specify in the declaration of the map?
The type of the objects you intend to store in the map.
map<std::string,void *¿?
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Victor Bazarov wrote:
Manuel wrote:
I need implement a map of member functions of some class.
This map is formed by a string and a pointer to the member function.
Member of what class? What arguments does it take? What type does
it return?
The members are of different class that derive of a superclass and this
members do
not return anything.
>
The problem is that the map need that the object saved are the same
type.
Right.
So what type to specify in the declaration of the map?
The type of the objects you intend to store in the map.
map<std::string,void *¿?
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Thanks for your fast reply
Manuel wrote:
Victor Bazarov wrote:
>Manuel wrote:
>>I need implement a map of member functions of some class. This map is formed by a string and a pointer to the member function.
Member of what class? What arguments does it take? What type does it return?
The members are of different class that derive of a superclass and
this members do
not return anything.
What's the point to have member functions of different classes stored
in the same container? What's _common_ about those functions? How
do you intend to use those map elements?
And if they don't return anything, the return value type is 'void'.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Victor Bazarov wrote:
Manuel wrote:
Victor Bazarov wrote:
Manuel wrote: I need implement a map of member functions of some class. This map is formed by a string and a pointer to the member function.
Member of what class? What arguments does it take? What type does
it return?
The members are of different class that derive of a superclass and
this members do
not return anything.
What's the point to have member functions of different classes stored
in the same container? What's _common_ about those functions? How
do you intend to use those map elements?
And if they don't return anything, the return value type is 'void'.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
The methods are used to get objects. This methods have the same name
and the same parameters. it is like a constructor.
I have got a xml file that specifies the objects that i want with his
state
In this file I have a label with the name of the class and the values
of his attributes.
So I parse the file and create the corresponding objects.
Victor Bazarov wrote:
Manuel wrote:
Victor Bazarov wrote:
Manuel wrote: I need implement a map of member functions of some class. This map is formed by a string and a pointer to the member function.
Member of what class? What arguments does it take? What type does
it return?
The members are of different class that derive of a superclass and
this members do
not return anything.
What's the point to have member functions of different classes stored
in the same container? What's _common_ about those functions? How
do you intend to use those map elements?
And if they don't return anything, the return value type is 'void'.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
The methods are used to get objects. This methods have the same name
and the same parameters. it is like a constructor.
I have got a xml file that specifies the objects that i want with his
state
In this file I have a label with the name of the class and the values
of his attributes.
So I parse the file and create the corresponding objects.
Manuel schrieb:
Victor Bazarov wrote:
>Manuel wrote:
>>Victor Bazarov wrote: Manuel wrote: I need implement a map of member functions of some class. This map is formed by a string and a pointer to the member function. Member of what class? What arguments does it take? What type does it return? The members are of different class that derive of a superclass and this members do not return anything.
What's the point to have member functions of different classes stored in the same container? What's _common_ about those functions? How do you intend to use those map elements?
And if they don't return anything, the return value type is 'void'.
V -- Please remove capital 'A's when replying by e-mail I do not respond to top-posted replies, please don't ask
The methods are used to get objects. This methods have the same name
and the same parameters. it is like a constructor.
I have got a xml file that specifies the objects that i want with his
state
So the methods are static functions?
That's an information we need to help you. Give an example of such a
class/function (a minimal example).
You can typedef your function type and put pointers to that in the map:
typedef void factory_t(baseclass&, const parameters&);
std::map< std::string, factory_t* your_map;
--
Thomas
Thomas J. Gritzan wrote:
Manuel schrieb:
Victor Bazarov wrote:
Manuel wrote: Victor Bazarov wrote: Manuel wrote: I need implement a map of member functions of some class. This map is formed by a string and a pointer to the member function. Member of what class? What arguments does it take? What type does it return? The members are of different class that derive of a superclass and this members do not return anything.
What's the point to have member functions of different classes stored
in the same container? What's _common_ about those functions? How
do you intend to use those map elements?
And if they don't return anything, the return value type is 'void'.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
The methods are used to get objects. This methods have the same name
and the same parameters. it is like a constructor.
I have got a xml file that specifies the objects that i want with his
state
So the methods are static functions?
That's an information we need to help you. Give an example of such a
class/function (a minimal example).
You can typedef your function type and put pointers to that in the map:
typedef void factory_t(baseclass&, const parameters&);
std::map< std::string, factory_t* your_map;
--
Thomas
well Thomas, you give me an idea to solve the problem.
i can create a static method in the factory class for each one of the
classes and then in the map it save the pointer to this methods.
So, when I need a object i call to factory::(*pointer)(const
paramaters&)
something as well as this:
typedef float (*MyFuncPtrType)(const paramaters&);
map<std::string, MyFuncPtrType>;
map["method1"] = &method1;
map["method2"] = &method2;
when i need a object i call: factory::(*map["method1"])(parameters).
I think that this can work. what do you think?
Manuel wrote:
Thomas J. Gritzan wrote:
>Manuel schrieb:
>>Victor Bazarov wrote: Manuel wrote: Victor Bazarov wrote: >Manuel wrote: >>I need implement a map of member functions of some class. >>This map is formed by a string and a pointer to the member >>function. >Member of what class? What arguments does it take? What type >does it return? The members are of different class that derive of a superclass and this members do not return anything. What's the point to have member functions of different classes stored in the same container? What's _common_ about those functions? How do you intend to use those map elements?
And if they don't return anything, the return value type is 'void'.
V -- Please remove capital 'A's when replying by e-mail I do not respond to top-posted replies, please don't ask
The methods are used to get objects. This methods have the same name and the same parameters. it is like a constructor. I have got a xml file that specifies the objects that i want with his state
So the methods are static functions? That's an information we need to help you. Give an example of such a class/function (a minimal example).
You can typedef your function type and put pointers to that in the map:
typedef void factory_t(baseclass&, const parameters&);
std::map< std::string, factory_t* your_map;
-- Thomas
well Thomas, you give me an idea to solve the problem.
i can create a static method in the factory class for each one of the
classes and then in the map it save the pointer to this methods.
So, when I need a object i call to factory::(*pointer)(const
paramaters&)
something as well as this:
typedef float (*MyFuncPtrType)(const paramaters&);
map<std::string, MyFuncPtrType>;
map["method1"] = &method1;
map["method2"] = &method2;
when i need a object i call: factory::(*map["method1"])(parameters).
I think that this can work. what do you think?
If I may... This sounds OK, only to take address of a member function
you need the class before the name:
map["method1"] = &OneClass::method1;
map["method2"] = &TwoClass::method2;
And when you call it, you can't prepend it with 'factory::'. You just
use
map["method1"](parameters);
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Victor Bazarov wrote:
If I may... This sounds OK, only to take address of a member function
you need the class before the name:
map["method1"] = &OneClass::method1;
map["method2"] = &TwoClass::method2;
And when you call it, you can't prepend it with 'factory::'. You just
use
map["method1"](parameters);
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Of course, you may.
well. I think that this is not neccesary because in the end the methods
will be of the same class.
i make this:
FACTORY_H
typedef void (*PtrMethod)(std::vector<std::string>);
class Factory
{
private:
map<const char*, PtrMethod*, ltstrtheMap;
protected:
Factory();
~Factory();
Object * method1(std::vector<std::string>);
Object * method2(std::vector<std::string>);
public:
Object *
getObject(std::string,std::vector<std::string>);
};
FACTORY_CPP
Factory::Factory()
{
map["method1"] = &method1;
map["method2"] = &method2;
}
Object * Factory::getObject(string label,vector<stringparamaters)
{
PtrMethod method = theMap[label];
Object * object = (*method)(parameters);
return energia;
}
is it correct? what do you think?
thank you very much by your attention
Manuel wrote:
[..]
well. I think that this is not neccesary because in the end the
methods will be of the same class.
i make this:
FACTORY_H
typedef void (*PtrMethod)(std::vector<std::string>);
class Factory
{
private:
map<const char*, PtrMethod*, ltstrtheMap;
protected:
Factory();
~Factory();
Object * method1(std::vector<std::string>);
Object * method2(std::vector<std::string>);
public:
Object *
getObject(std::string,std::vector<std::string>);
};
FACTORY_CPP
Factory::Factory()
{
map["method1"] = &method1;
map["method2"] = &method2;
}
Object * Factory::getObject(string label,vector<stringparamaters)
{
PtrMethod method = theMap[label];
Object * object = (*method)(parameters);
return energia;
}
is it correct? what do you think?
Close, but incorrect. If your 'method1' and 'method2' return Object*,
you cannot declare 'PtrMethod' as returning "void". You have to make
sure the type is the same as the functions. That's the glaring error.
Then 'Factory::getObject' returns 'energia' where it should probably
return 'object'.
Not so important ones include passing by value where passing by const
reference should be sufficient.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Victor Bazarov wrote:
Manuel wrote:
[..]
well. I think that this is not neccesary because in the end the
methods will be of the same class.
i make this:
FACTORY_H
typedef void (*PtrMethod)(std::vector<std::string>);
class Factory
{
private:
map<const char*, PtrMethod*, ltstrtheMap;
protected:
Factory();
~Factory();
Object * method1(std::vector<std::string>);
Object * method2(std::vector<std::string>);
public:
Object *
getObject(std::string,std::vector<std::string>);
};
FACTORY_CPP
Factory::Factory()
{
map["method1"] = &method1;
map["method2"] = &method2;
}
Object * Factory::getObject(string label,vector<stringparamaters)
{
PtrMethod method = theMap[label];
Object * object = (*method)(parameters);
return energia;
}
is it correct? what do you think?
Close, but incorrect. If your 'method1' and 'method2' return Object*,
you cannot declare 'PtrMethod' as returning "void". You have to make
sure the type is the same as the functions. That's the glaring error.
Then 'Factory::getObject' returns 'energia' where it should probably
return 'object'.
Not so important ones include passing by value where passing by const
reference should be sufficient.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Oh, you are rigth. I had an error: "PtrMethod" return "Object *" and
"Factory::getObject" returns a Object*. I'm mistaken when copying the
source.
and too, you are rigth with passing by value or by const reference. I
will do it thus
Thank you very much for your help. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Fu Bo Xia |
last post by:
the java.lang.Object.forName method takes a java class name and returns a
Class object associated with that class.
eg. Class myClass = Object.forName("java.lang.String");
by if i only know the...
|
by: Vijay Singh |
last post by:
How do you instantiat a class with a Class.forName( ) method, if the class's
default constructor requires a parameter?
|
by: Gavin Andrews |
last post by:
I use log4j for logging and tend to include the following snipet in
all my classes...
public class MyClass {
// Logging Declarations
private static String _className;
private static Category...
|
by: Phoneix |
last post by:
Hello ,
I have a necessity to delete a jar file which is in the CLASSPATH.
But JVM locks it after a class.forName() call, even though the class
loaded is NOT in the JAR file I want to delete. ( I...
|
by: Alex Hunsley |
last post by:
Does python provide a way to dynamically use modules and/or classes?
I'm thinking in the vein of Java's Class.forName.
As a pseudocode example, I'm looking for the following ability:
...
| |
by: Mandar |
last post by:
How do i instantiate a class if I get the name of the class at runtime ?
I am looking for something like class.forname("classABC") in Java .
TIA
Mandar
|
by: jean-francois |
last post by:
In java you can do it with
Class.forName("myClass").newInstance();
this will return you a new instance of the class myClass, provided that
you defined it elsewhere. How can I get this in c++...
|
by: vasavimaruthi |
last post by:
hi,
i got class not found exception of a small jdbc program in windows.
the program is like this
import java.sql.*;
public class Db1
{
public static void main(String a)...
|
by: illu1985 |
last post by:
package area;
import java.sql.*;
import java.util.*;
public class area
{
int id;
public void setId(int id)
{
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |