i have a problem , i need to use a function named getentityposition which is in some file for example named AgentActioncomponent ,when i want to call this function i am available with AgentActioncomponent and even getentityposition...i call it in this way
******************************************************************
Vec3f currentPos = AgentActionComponent::getEntityPosition(m_characterID2);
******************************************************************
but it doesnt recognize AgentActionComponent .. when i take my cursor to AgentActionComponent it says non static member reference
must be relative to a specific object ....
Exactly what the error says. The function you are calling is a non-static function, so you can only use this function when it's part of a already created object.
Exactly what the error says. The function you are calling is a non-static function, so you can only use this function when it's part of a already created object.
1. Well ! i have tried the way u told me but when i m creating object it doesnt recognize object
To make my question more clear .........
2. the AgentActionComponent is a headerfile which has another .cpp file with the same name
the header file contains declaration about function getentityposition and .cpp file contains
definition ....
i don't know but i guess there is some connection missing some where....
1. Well ! i have tried the way u told me but when i m creating object it doesnt recognize object
To make my question more clear .........
2. the AgentActionComponent is a headerfile which has another .cpp file with the same name
the header file contains declaration about function getentityposition and .cpp file contains
definition ....
i don't know but i guess there is some connection missing some where....
Kindly help
Regards Imran Habib
Your question is clear, your understanding of the problem isn't.
You're trying to call a non-static member function of a class. To do that, you need an instantiation of the class - an object. You're trying to call the function as if it were static and it's clearly not defined that way. It's not a header/cpp issue, it's a not calling the function properly issue.
Can you post the code where you tried to create an object?
Your question is clear, your understanding of the problem isn't.
You're trying to call a non-static member function of a class. To do that, you need an instantiation of the class - an object. You're trying to call the function as if it were static and it's clearly not defined that way. It's not a header/cpp issue, it's a not calling the function properly issue.
Can you post the code where you tried to create an object?
here we go
*****************************************
AgentActionComponent Obj;
Obj.getEntityPosition(m_characterID2);
*****************************************
it says no default constructor .............. on taking cursor to Obj .. i tried delcaring default constructor
but it doesnt work yet ...........
any suggestions
*****************************************
AgentActionComponent Obj;
Obj.getEntityPosition(m_characterID2);
*****************************************
it says no default constructor .............. on taking cursor to Obj .. i tried delcaring default constructor
but it doesnt work yet ...........
any suggestions
Stop telling us you tried stuff and it didn't work without showing the code.
The error messages mean something. Obviously you need to create a default constructor. Show us what you did and we'll tell you why it didn't work.
Stop telling us you tried stuff and it didn't work without showing the code.
The error messages mean something. Obviously you need to create a default constructor. Show us what you did and we'll tell you why it didn't work.
AgentActioncomponent* Obj;
Obj->getentityposition;
now i dun have error but i have another problem in it and it is linking problem....
actually as far as i know if we need to access a member function in from header file we need to
1. add header .h as an header in .cpp
2. we have to call constructor of the class , (the same class whose member function we are calling) in our .cpp
3. adding refernce to .h file
I did 1 and 3 .. but i am confused about doing 2 ... because it has no default constructor I mean constructor with out parameters and its other constructor eg AgentActioncomponent(GameEntity* ABC)
can be used or not in my .cpp
Lastly :::: I CREATED my default constructor in that header file but i dun get when i call that default constructor ....
if u can help plz kindly let me know , how should i solve this prob
2. we have to call constructor of the class , (the same class whose member function we are calling) in our .cpp
This is not true.
3. adding refernce to .h file
What do you mean by "reference to .h file"?
I did 1 and 3 .. but i am confused about doing 2 ... because it has no default constructor I mean constructor with out parameters and its other constructor eg AgentActioncomponent(GameEntity* ABC)
can be used or not in my .cpp
None of what you stated makes sense.
Here is an example of code where 2) is not necessary:
Where do you see a default constructor being called for s? That code will compile just fine. As for 3) in your description, I have no idea what you're referring to.
Obj is an unitialized pointer.
Obj->getentityposition is trying to dereference an unitialized pointer which will almost always cause your program to crash.
When you call a function, you need to put parens after the function name, and include applicable arguments between the parens.
There's been a rash of people here lately trying to program by guessing. That will never work. Get a good book and work through it.
AgentActioncomponent* Obj;
Obj->getentityposition;
now i dun have error but i have another problem in it and it is linking
problem....
Well, actually you managed to cheat the compiler this way, and you don't have a compilation error now, but you still do have error, and linking problem is the smallest part of it. Even if you manage somehow to link that, your code is 100% going to crash at runtime because of uninitialized pointer.
actually as far as i know if we need to access a member function in from header file we need to
1. add header .h as an header in .cpp
2. we have to call constructor of the class , (the same class whose member function we are calling) in our .cpp
3. adding refernce to .h file
I did 1 and 3 .. but i am confused about doing 2 ... because it has no default constructor I mean constructor with out parameters and its other constructor eg AgentActioncomponent(GameEntity* ABC)
can be used or not in my .cpp
Lastly :::: I CREATED my default constructor in that header file but i dun get when i call that default constructor ....
if u can help plz kindly let me know , how should i solve this prob
Sorry, no intention to offend anyhow. It's obvious you do not understand pointers, constructors, and something makes me believe your do-not-understand list does not end with those. And the best solution to your problem would be to go back and start learning C++ from the very beginning, get some fundamental reading on C++ and do not skip doing exercises disregarding how boring those would seem to you.
Last edited by Igor Vartanov; March 26th, 2011 at 03:01 PM.
Bookmarks