This works if the function pointer being passed to the event manager is not a member function.
I have two other classes Scene and Object that could potentially use this EventManager to create callback events. Scene and Object are both pure virtual objects. How can I pass a pointer to a member function of the child classes of both Scene and Object? I am fine with just having two separate watchEvent functions for Scene and Object but how do I pass the type of the Object or the type of the Scene? The child classes are unknown as they are being created by someone using this game engine.
For example, if I want to make a player object it would be something like
class PlayerObject : public Object{...};
Now that PlayerObject type has to find its way to PlayerObject::functionToCall(). I think I need templates to do this but, since I never used them before
This is how I intend to use this
class OtherScene : public Scene{ void p_pressed(void){ //pause }
This creates quite a mess. It seems that somehow the "vector" declaration isn't working as the referenced web link seems to suggest that it should. I presume that, as usual, clearing one real error will eliminate the cascade of errors the first real error produces. Why won't VC++ accept the "vector" identifier?
The error messages that follow the build attempt are:
Friedman.cpp d:documents and settingsxxmy documentsvisual studio 2010projectsfriedmanfriedmanEinstein.h(22): warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS.
I have started working with structures so here's a side project from my text book. It's purpose is fairly simple; it asks for the sales of each quarter of the year from 4 different divisions and then calculates the average quarterly sales and total annual sales and finally displays all the data. My problem is that in the function "displayCompanyInfo" the statement
std::cout << "Division " << R.division_name << std::endl; does not display the name of the division. With that in mind here is the code: #include <iostream> #include <string> struct CompanyInfo {
[Code]....
As you can see the last part of the output has statements that say "Division" however they do not say the name of the division afterwards. I don't understand why that is?
template <typename T> struct avl_tree { T data; int balance; struct avl_tree <T> *Link[2]; static int (*comp)(T, T); };
In main, I have a function like so: int compare(int a, int b) { return ( a - b ); }
Now how do I assign the function pointer in my avl_tree class to the compare function?
I did this: int (avl_tree<int>::*comp)(int, int) = compare;
But I got the compiler error: Tree_Test.cc: In function ‘int main()’: Tree_Test.cc:27:42: error: cannot convert ‘int (*)(int, int)’ to ‘int (avl_tree<int>::*)(int, int)’ in initialization
Code: typedef struct _a { int id; } a; typedef struct _b { a my_a; my_a.id = 1; // error: expected specifier-qualifier-list before "my_a" } b;
I get error: expected specifier-qualifier-list before "my_a"
I must set the id for the kind of struct created inside the struct def because main() will be casting based on this id. Thats how I will know which structure b contains by it's id, there could be hundards of different structs with different values I will cast to the correct one and know it's members by it's id. How do I ?
I have a question regarding composition and accessing members "deep" inside the composed structure. For example;
class A { private: int m_myInt; public: int myInt() const {return this->m_myInt;}; void myInt(int newInt) {this->m_myInt = newInt;};
[Code] ....
Now, from somwhere I have access to an object of type B where I want to update the A::m_myInt. How would you do this without "breaking" the whole purpose of private/public members?
B myB; myB.m_a.myInt(3); // Not allowed, and not desireable
I thought about implementing access through functons kind of like;
A & B::a() {return this->m_a;}; myB.a().myInt(3);
but I'm worried that this exposes my B::m_a-object too much. This would allow
myB.a() = A(); , right?
The following is a more desireable way of acces, but doesn't work for updating;
A const & B::a() {return this->m_a;}; myB.a().myInt(3); //Disallowed? myInt(int) is non-const.
What about this? Is this a good way of doing it?
class A { private: int m_myInt; public: int myInt() const {return this->m_myInt;};
[Code] ....
I guess it works? It would lead to a lot of data shuffling in case of larger sub-components.I would really like to do the following without exposing my components so much:
Is there way to find the size of structure pointer size? When we tried to get the size of structure pointer will get size of address(@ location) which would be 4 bytes long. But I want to get the size of all structure members size using structure pointer.
This is a code snippet extracted from C++ Primer Plus book. However, it is really confusing. I don't really understand the free_throws * pt;
as far as I know, a pointer has to point to a memory address, and it is best to initialize it when it is declared. However, according to the code snippet above, the pt isn't initialized to any address. Isn't it dangerous when we declare a pointer without initializing it before we use it?
I thought it is supposed to be like this
free_throw * pt = new three_throw; // or free_throw * pt = & ft;
I am trying to wright a program that takes student grade data from a command line file, calculates a final grade, and copies the final grades to an output file. So far I have two functions, one that creates a student structure by allocating memory for it and returning its address, and one that should take that address and fill it with data from a line from the input file. My ultimate goal is to use a linked list to connect all the structs, but for now I just want to get the functions working. When I run what I have so far, I get an error C2440 (using visual 2010) that says "cannot convert from 'cStudent *', to 'cStudent', and points to the line where I call my fill function. How should structure pointers be passed?
I'm trying to call a function via a function pointer, and this function pointer is inside a structure. The structure is being referenced via a structure pointer.
Code:
position = hash->(*funcHash)(idNmbr);
The function will return an int, which is what position is a type of. When I compile this code,
I get the error: error: expected identifier before ( token.
Is my syntax wrong? I'm not sure what would be throwing this error.
error: request for member 'character' in '* ptr', which is of non-class type 'datastructure*' error: request for member 'character' in '* ptr', which is of non-class type 'datastructure*'
These errors are related to " *ptr->character='a'; printf("Ptr: %c",*ptr->character); "
I want to access "character" data inside the structure "trial" by a pointer to pointer "ptr" inside function "function",but I couldn't find a way to do this.
#include "stdafx.h" #include <iostream> #include <math.h> using namespace std; class Calc {
[Code] ....
when i built it, it showed the following errors:
1>------ Build started: Project: rough, Configuration: Debug Win32 ------ 1> rough.cpp 1>e:c programs ough ough ough.cpp(17): error C3872: '0xa0': this character is not allowed in an identifier 1>e:c programs
"You cannot initialize the static data member in the class definition — that’s simply a blueprint for an object and initializing values for members are not allowed. You don’t want to initialize it in a constructor, because you want to increment it every time the constructor is called so the count of the number of objects created is accumulated."
Why don't you want to initialize it in a constructor?
Edit: Because every time it is called it will set it back to 0 or whatever the initializing value.