thanks for the ans boys
Jay03
Posts
-
Enumerated types -
Enumerated typesHey guys, I was wondering if u can have a user defined type such as: public enum Pizza { SMALL = 5.99, M = 7.99, L = 9.99 }; I am not quite sure if you can declare double variables inside the Pizza type? I believe someone can help :confused:
-
Finding number of occurences in a list of numbersthanks, thats great i got a bit confused when I first saw your code, but....... it works!!! THANKS !!!!!!! :-D:-D:-D:-D:-D:-D:-D:-D:-D:-D:-D:-D:-D:rose::rose:
-
Finding number of occurences in a list of numbershey guys, I was wondering what the most efficient way of finding the number of occurences in a list is. Say I have a list.... struct data{ int number; int occurences; }; data list[7]; list[0].number = 5; list[1].number = 6; list[2].number = 6; list[3].number = 8; list[4].number = 9; list[5].number = 9; list[6].number = 9; how would i sort in such a way that I eliminate the numbers that occur more than once like this, list[0].number = 5; list[1].number = 6; list[2].number = 8; list[3].number = 9; and saves the number of occurence for each number list[0].occurences = 1; list[1].occurences = 2; list[2].occurences = 1; list[3].occurences = 3; I thought of every possible way, I can do it for numbers that appear twice but three times, i duno how to deal with it..... Someone please help me out :doh::doh::doh::doh::doh::doh::confused::confused::confused:
-
Reading from a file inputHey guys, I am suppose to read in from a text file. M is the sex and 24 is the age. The file I'm currently reading has the following code. I am wondering what the ws is for. I see how fin >> sex is reading in the sex of the person and fin >> swimmer[actualSwimmers].age is reading in the age. What is the >> ws doing there??? Someone please help me out here thanks in advance. M 24 fin >> sex; fin >> swimmers[actualSwimmers].age >> ws;
-
main parameters.........Hey guys, I was wondering when we use these parameters (int argc, char *argv[]) in a main function? I have no clue why they use it.... Thanks in advance
void main (int argc, char *argv[]) { .......... ......... }
-
calling a function two waysit does actually...... does
take away the preprocessor statements
-
calling a function two waysRTI::AttributeHandleValuePairSet* Ball::createNVPSet()
{
RTI::AttributeHandleValuePairSet* pBallAttributes = NULL;//! Make sure the RTI Ambassador is set.
if ( ms_rtiAmb ) // if ms_rtiAmb!=NULL
{
pBallAttributes = RTI::AttributeSetFactory::create( 4 );pBallAttributes->add( Ball::ms_ballLocationXId,
(char*)&this->m_currentState.x,
sizeof(double) );
pBallAttributes->add( Ball::ms_ballLocationYId,
(char*)&this->m_currentState.y,
sizeof(double) );
pBallAttributes->add( Ball::ms_ballVelocityXId,
(char*)&this->m_currentState.vx,
sizeof(double) );
pBallAttributes->add( Ball::ms_ballVelocityYId,
(char*)&this->m_currentState.vy,
sizeof(double) );
}//! pClockAttributes is allocated on the heap and must be
//! deallocated by the calling function
return pBallAttributes;
}void Ball::sendUpdate()
{
if ( m_nextStateCalculated == RTI::RTI_TRUE )
{
m_currentState = m_nextState;
m_nextStateCalculated = RTI::RTI_FALSE;try
{
/*!
* In order to send the values of our attributes, we must
* construct an AttributeHandleValuePairSet (AHVPS) which
* is a set comprised of attribute handles, values, and
* the size of the values.
*/
RTI::AttributeHandleValuePairSet* pNvpSet = createNVPSet();
/*!
* Send the AHVPS to the federation.
*
* this call returns an event retraction handle but we
* don't support event retraction so no need to store it.
*/
(void) ms_rtiAmb->updateAttributeValues( getInstanceId(),
*pNvpSet,
NULL );
//! Must free the memory
pNvpSet->empty();
delete pNvpSet;
}
catch ( RTI::Exception& e )
{
cerr << "BALL: Error:" << &e << endl;
}
}
}void Ball::update(
RTI::InteractionClassHandle theInteraction,
const RTI::ParameterHandleValuePairSet& theParameters )
{
if (ms_rtiAmb) // if ms_rtiAmb!=NULL
{
if ( theInteraction == Ball::ms_clockTickId )
{
RTI::ParameterHandle paramHandle;
RTI::ULong valueLength;//! We need to iterate through the AttributeHandleValuePairSet
//! to extract each AttributeHandleValuePair. Based on the type
//! specified ( the value returned by getHandle() ) we need to
//! extract the data frlom the buffer that is returned by
//! getValue().
for ( unsigned int i = 0; i < theParameters.size(); i++ )
{
paramHandle = theParameters.getHandle( i );
if ( paramHandle == Ball::ms_clockTickIntervalId )
{
double timeInterval = 1 / 60.0;
theParameters.getValue( i, (char*)&timeInterval, valueLength );//! Update all clock objects
for ( unsigned int j = 0; j < ms_numInstances; j++ )
{
( *( (Ball*)(ms_instances[ -
calling a function two waysRTI::AttributeHandleValuePairSet* Ball::createNVPSet() { RTI::AttributeHandleValuePairSet* pBallAttributes = NULL; //! Make sure the RTI Ambassador is set. if ( ms_rtiAmb ) // if ms_rtiAmb!=NULL { pBallAttributes = RTI::AttributeSetFactory::create( 4 ); pBallAttributes->add( Ball::ms_ballLocationXId, (char*)&this->m_currentState.x, sizeof(double) ); pBallAttributes->add( Ball::ms_ballLocationYId, (char*)&this->m_currentState.y, sizeof(double) ); pBallAttributes->add( Ball::ms_ballVelocityXId, (char*)&this->m_currentState.vx, sizeof(double) ); pBallAttributes->add( Ball::ms_ballVelocityYId, (char*)&this->m_currentState.vy, sizeof(double) ); } //! pClockAttributes is allocated on the heap and must be //! deallocated by the calling function return pBallAttributes; } void Ball::sendUpdate() { if ( m_nextStateCalculated == RTI::RTI_TRUE ) { m_currentState = m_nextState; m_nextStateCalculated = RTI::RTI_FALSE; try { /*! * In order to send the values of our attributes, we must * construct an AttributeHandleValuePairSet (AHVPS) which * is a set comprised of attribute handles, values, and * the size of the values. */ RTI::AttributeHandleValuePairSet* pNvpSet = createNVPSet(); /*! * Send the AHVPS to the federation. * * this call returns an event retraction handle but we * don't support event retraction so no need to store it. */ (void) ms_rtiAmb->updateAttributeValues( getInstanceId(), *pNvpSet, NULL ); //! Must free the memory pNvpSet->empty(); delete pNvpSet; } catch ( RTI::Exception& e ) { cerr << "BALL: Error:" << &e << endl; } } } void Ball::update( RTI::InteractionClassHandle theInteraction, const RTI::ParameterHandleValuePairSet& theParameters ) { if (ms_rtiAmb) // if ms_rtiAmb!=NULL { if ( theInteraction == Ball::ms_clockTickId ) { RTI::ParameterHandle paramHandle; RTI::ULong
-
calling a function two waysIs my initial argument correct now?
-
calling a function two wayssorry im missing some detail. The function createNVPSet is a member of class Ball. PairSet* Ball::CreateNVPSet() { ............ ............ return set; }
-
calling a function two wayssorry im missing some detail. The function createNVPSet is a member of class Ball. PairSet* Ball::CreateNVPSet() { ............ ............ return set; }
-
calling a function two waysHey guys, I don't see the difference in using two different ways of calling a function. in the function send, you are creating a pair of set by calling the function creatNVPSet(); In the function update, you are creating a pair of set by first creating a pointer to a Ball object and then using the pointer pBall to call upon the member function createNVPSet(); What's the point of doing that? Can both of the function just create the set by using createNVPSet(); instead of using pBall->creatNVPSet(); thanks in advance :) PairSet* CreateNVPSet() { ............ ............ return set; } void send (int x, int y) { PairSet* pNvpSet = createNVPSet(); ................ ............. } void update (int a, int b) { Ball *pBall; PairSet* pNvpSet = pBall->createNVPSet(); ........... ........ }
-
[Message Deleted][Message Deleted]
-
[Message Deleted][Message Deleted]
-
Object DefinitionZac Howland wrote:
This syntax is creating a function pointer
Won't it be typedef void UpdateHandlerPtr (ObjectRootPtr, const RTI::AttributeHandleValuePairSet&); or typedef void (UpdateHandler*) (ObjectRootPtr,const RTI::AttributeHandleValuePairSet&);
-
Object Definitiontypedef UpdateHandler* UpdateHandlerPtr;
I saw this code in a project file but I couldn't find what the definition of UpdateHandler is. It is not defined anywhere. Only thing I found on UpdateHandler is the code below What does the syntax below do?typedef void UpdateHandler(ObjectRootPtr, const RTI::AttributeHandleValuePairSet&);
-
Syntax problemsHey Rage, thanks for the reply What if you had a situation where you had two functions of the same parameters (obj, theAttributes). How does the pointer know which function to point to?
Rage wrote:
(*ms_updateHandlers[i]) points on function number i in the array.
I thought ms_updateHandlers is an array of pointers therefore i is a pointer number Thanks
-
Syntax problemsvoid ObjectRoot::runUpdateHandlers( ObjectRootPtr obj, const RTI::AttributeHandleValuePairSet& theAttributes ) { if (obj) { for (unsigned int i=0; i < ObjectRoot::ms_numUpdateHandlers; i++) { if (ObjectRoot::ms_updateHandlers[i]) {
(*ms_updateHandlers[i])(obj, theAttributes);
} } } } I don't understand what the code highlighted in brown does....... I am a beginner... please help me out Thanks -
Syntax problemViorel. wrote:
The ms_instances array contains pointers to Ball objects
What happens when j = 0;
Ball * const ball = ms_instance[0];
Does this mean it has no pointers because ms_instance[0] ? Do you need atleast j = 1 to create a pointer ........ like ms_instance[1] means 1 pointer .... ms_instance[2] means array of two pointers......... so what does 0 mean?ball->m_stateTimeInterval = timeInterval;
-------------------------------------------------------------------------------------------- So for each j value, there will be an array of pointers created?