|
Given your company's policies it is quite difficult to help you. Please post an equivalent code snippet.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
I've to declare a function which is already defined in another class. I don't want to inherit from the existing class. The function is under a namespace in the first file. When I declare the function in the new class, I got the following errors:
d:\character\test.h(84) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
d:\character\test.h(84) : error C2143: syntax error : missing ',' before '*'
I've declared the function in the public section only. How do I declare the function in the second class?
|
|
|
|
|
He didn't ask you to repeat your question - he asked you for some actual CODE.
If you can't post the actual code, try recreating the problem with similar code - this is probably a good idea anyway. I'm guessing your code is more than 10 lines long anyway. And by recreating the problem, you may even see your own soloution.
If you only post the error message, it is very unlikely anyone can or will help you.
Iain.
|
|
|
|
|
The function I want to declare is inside a namespace. It's coded like this:
namespace dtAI
{
void AICharacter::GoToWaypoint(float dt, const Waypoint* pWaypoint)
{
mCharacter->RotateToPoint(pWaypoint->GetPosition(), dt * 3.0f);
mCharacter->SetSpeed(-float(mSpeed));
if(!mCharacter->IsAnimationPlaying("Run"))
{
mCharacter->ClearAllAnimations(0.5f);
mCharacter->PlayAnimation("Run");
}
}
}
This function is declared in the header file under public section as below :
void GoToWaypoint(float dt, const Waypoint* pWaypoint);
I've to declare the function in some other header file. I can comment the function in the first file. When I declare the function in the second file, I got the above mentioned errors. What to do?
|
|
|
|
|
OK, I'm not much clearer, as you haven't show all the places.
But to expand on Alan Balkany's answer to you, I've done a similar solution to the one he proposes (though I didn't know it had a name).
namespace Iain
{
class CIain
{
virtual BOOL DoSomethingExciting (char a, int b, void *p) = 0;
}
CIain *GetAnIainInterface ();
};
Now we have a pure virtual class and interface. Let's try and use it!
#include "Iain.h"
...
CIain *pIain = Iain::GetAnIainInterface ();
ASSERT(pIain);
pIain->DoSomethingExciting ('a', 97, NULL);
...
So far so good - but we need to actually implement it somewhere!
#include "Iain.h"
class CIainImpl : public Iain::CIain
{
....
virtual BOOL DoSomethingExciting (char a, int b, void *p)
{
return TRUE;
}
};
CIainImpl m_Iain;
Iain::GetAnIainInterface ()
{
return &m_Iain;
}
I hope that helps a little as an example!
Iain.
|
|
|
|
|
See here [^] (Iain expresses what I think even better than I'm able to ).
Probably the errors occurred have nothing to do with you requirement to include in a new class a method having the same name of some other class's method. This is the reason we're asking for the code. For sure we have no intention at all to copy it.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Sorry Gentlemen! I told my company's policies only. I never think anybody will copy my code. I feel really sorry if I hurt anybody.
|
|
|
|
|
Don't worry. Just kidding. Anyway if you can post a simple sample code emulating your troubled one...
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Here it is:
The function I want to declare is inside a namespace. It's coded like this:
namespace dtAI
{
void AICharacter::GoToWaypoint(float dt, const Waypoint* pWaypoint)
{
mCharacter->RotateToPoint(pWaypoint->GetPosition(), dt * 3.0f);
mCharacter->SetSpeed(-float(mSpeed));
if(!mCharacter->IsAnimationPlaying("Run"))
{
mCharacter->ClearAllAnimations(0.5f);
mCharacter->PlayAnimation("Run");
}
}
osg::Vec3 AICharacter::GetPosition() const
{
osg::Matrix mat = mCharacter->GetMatrixNode()->getMatrix();
osg::Vec3 pos(mat(3, 0), mat(3, 1), mat(3, 2));
return pos;
}
}
This function is declared in the header file under public section as below :
void GoToWaypoint(float dt, const Waypoint* pWaypoint);
I've to declare the function in some other header file. I can comment the function in the first file. When I declare the function in the second file, I got the above mentioned errors. What to do?
|
|
|
|
|
T.RATHA KRISHNAN wrote: void GoToWaypoint(float dt, const Waypoint* pWaypoint);
The above declaration doesn' correnspond to the definition, unless it is enclosed inside the same namespace(dtAI ) and class(AICharacter ).
What do you need to do? Declare another function with the same signature outside the namespace?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
I've to declare the function in another file not only the signature but I need the functionalites also in the function that is to be declared by me in the second file.(I can comment the function inside the first file i.e included in the namespace).
|
|
|
|
|
Ahh, it was so much clearer the second time!
You might consider the Facade design pattern (http://en.wikipedia.org/wiki/Facade_pattern[^]) to give one class access to a single function another class, without coupling the classes together.
The basic idea is to declare an interface that defines the one function, and make the existing class derive from that interface. The class that uses this function sees an instance of the existing class as the interface -- not the whole class.
|
|
|
|
|
I import class from excel.exe in office 2003.
In the program, I use only basic operations to manipulate .xls files.
Will the program be compatible with .xls file create with other versions of Excel, for example Excel 2000 or 2007?
system
|
|
|
|
|
Excel 2007 has many changes i.e ribbon bar , but as far as just programming excel is concern , think a program with excel 2003 should work with excel 2007 .
Vikas Amin
My First Article on CP" Virtual Serail Port "[^]
modified on Thursday, July 24, 2008 5:33 PM
|
|
|
|
|
Is there any API through which processes can be enumerated on the basis of Port they are using.
Thanx
Sunit
never say die
|
|
|
|
|
i feel this API <GetExtendedTcpTable> will work for me.If any body has another solution please let me know
Sunit
never say die
|
|
|
|
|
|
Thanx a lot
never say die
|
|
|
|
|
Hi!
I've two unrelated classes named "character" and "test". I've defined a variable "flag" inside test. I've to access this variable from the other class(i.e from "character"). For this I've declared the class "character" as friend in test.h in the private section.
i.e
friend class AICharacter;
and I've also forward declared the class test in character like this:
class test;
I've used the following code to access the variable:
test friend_test = new test();
friend_test->char_flag1 = false;
But it shows the following errors:
(i)error C2079: 'friend_TestAI' uses undefined class 'TestAI'
(ii)error C2512: 'TestAI' : no appropriate default constructor available
(iii) left of '->char_flag1' must point to class/struct/union/generic type
Is there any other way to access a variable which is declared inside some other class?
|
|
|
|
|
Code missing in your post.
I don't see any TestAI class in posted code.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Sorry. It's advised by my organisation not to post original code. Here is the modified post:
Hi!
I've two unrelated classes named "character" and "test". I've defined a variable "flag" inside test. I've to access this variable from the other class(i.e from "character"). For this I've declared the class "character" as friend in test.h in the private section.
i.e
<pre>friend class character;</pre>
and I've also forward declared the class test in character like this:
<pre>class test;</pre>
I've used the following code to access the variable:
<pre> test friend_test = new test();
friend_test->char_flag1 = false;</pre>
But it shows the following errors:
(i)error C2079: 'friend_test' uses undefined class 'test'
(ii)error C2512: 'test' : no appropriate default constructor available
(iii) left of '->char_flag1' must point to class/struct/union/generic type
Is there any other way to access a variable which is declared inside some other class?
|
|
|
|
|
It looks like you simply didn't include the 'test' header file. Forward declarations aren't enough when you need an instance of the object.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
I've included "test.h" also in character.h. Now it shows the following errors:
error C2440: 'initializing' : cannot convert from 'test *' to 'test'
No constructor could take the source type, or constructor overload resolution was ambiguous
.\character.cpp(124) : error C2819: type 'test' does not have an overloaded member 'operator ->'
d:\backupdelta3d\charactercontrol\test.h(40) : see declaration of 'test'
did you intend to use '.' instead?
.\character.cpp(124) : error C2232: '->test::char_flag1' : left operand has 'class' type, use '.'
Build log was saved at "file://d:\BackupDelta3D\AICharacterControl\Release\BuildLog.htm"
CharacterAnimation - 3 error(s), 0 warning(s)
Shall I use extern instead of friend? Which is good?
|
|
|
|
|
T.RATHA KRISHNAN wrote: error C2440: 'initializing' : cannot convert from 'test *' to 'test'
Well, the compiler is (of course) right, change the wrong lines (I earlier overlooked the mistake)
test friend_test = new test();
friend_test->char_flag1 = false;
to
test friend_test;
friend_test.char_flag1 = false;
or to
test * pfriend_test = new test();
pfriend_test->char_flag1 = false;
delete pfriend_test;
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
OK.Thank u. What is ur opinion on using extern inplace of friend keyword?
|
|
|
|