Re: [osg-users] STL vectors and function calls

2007-12-31 Thread Wu Xiaodong
*MyIterator->AnotherMethod();  should be "  MyIterator->AnotherMethod(); "



On Dec 30, 2007 12:47 AM, Renan Mendes <[EMAIL PROTECTED]> wrote:

> Hi, everyone.
>
> I've got  quick question on STL vectors.
>
> I've created a class (let's call it MyClass) with the method 'bool
> MyMethod(std::vector MyVector)' that calls another method 'void
> AnotherMethod()' that makes a simple check on a variable inherent to every
> instance of MyClass.
>
>
> How do I write that method? Or better put: how do I change the following
> code to make it right?
>
> bool MyClass::MyMethod(std::vector MyVector)
> {
>   std::vector::iterator MyIterator;
>
>   for(MyIterator = MyVector.begin(); MyIterator != MyVector.end();
> MyIterator++)
>  {
> *MyIterator->AnotherMethod();
>  }
> }
>
> I read that an iterator was a pointer to the content of the vector, why
> doesn't it work?
>
>
> Thanks,
>
>
> Renan M Z Mendes
>
> ___
> osg-users mailing list
> osg-users@lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
>


-- 
吴晓东
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] STL vectors and function calls

2007-12-29 Thread Renan Mendes
Thanks, Gordon.
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] STL vectors and function calls

2007-12-29 Thread Gordon Tomlinson
HI
 
Not really an OSG question this really belongs on a C++ user list, 
 
 
Note the function declaration bool MyClass::MyMethod(std::vector
MyVector) here you should be passing in your vector as a reference or
pointer, you should ALWAYS pass any none POD variables as a references or
even the evil pointer ( we shall ignore constness at this point : ) )  you
are actually making a full copy  of your vector and all it contents as shown

 
As defined you need something like ((MyClass&)(MyIterator)).AnotherMethod()
; note the DOT operator is used here not the -> operator. this is because
you vector as shown does not contain pointers
 
you might want to change your vectors declaration to use class pointers
rather class instances and pass by reference
 
If you were using pointers then you would be able to use the deference
operator
 
 

__
Gordon Tomlinson 

Email   : [EMAIL PROTECTED]
Website : www.vis-sim.com www.gordontomlinson.com 


__

"Self defence is not a function of learning tricks 
but is a function of how quickly and intensely one 
can arouse one's instinct for survival" 
-Master Tambo Tetsura 

 

  _  

From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Renan
Mendes
Sent: 29 December 2007 16:48
To: OSG Mailing List
Subject: [Norton AntiSpam] [osg-users] STL vectors and function calls


Hi, everyone.

I've got  quick question on STL vectors.

I've created a class (let's call it MyClass) with the method 'bool
MyMethod(std::vector MyVector)' that calls another method 'void
AnotherMethod()' that makes a simple check on a variable inherent to every
instance of MyClass. 


How do I write that method? Or better put: how do I change the following
code to make it right?

bool MyClass::MyMethod(std::vector MyVector)
{
  std::vector::iterator MyIterator; 

  for(MyIterator = MyVector.begin(); MyIterator != MyVector.end();
MyIterator++)
 {
*MyIterator->AnotherMethod();
 }
}

I read that an iterator was a pointer to the content of the vector, why
doesn't it work? 


Thanks,


Renan M Z Mendes

___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


[osg-users] STL vectors and function calls

2007-12-29 Thread Renan Mendes
Hi, everyone.

I've got  quick question on STL vectors.

I've created a class (let's call it MyClass) with the method 'bool
MyMethod(std::vector MyVector)' that calls another method 'void
AnotherMethod()' that makes a simple check on a variable inherent to every
instance of MyClass.


How do I write that method? Or better put: how do I change the following
code to make it right?

bool MyClass::MyMethod(std::vector MyVector)
{
  std::vector::iterator MyIterator;

  for(MyIterator = MyVector.begin(); MyIterator != MyVector.end();
MyIterator++)
 {
*MyIterator->AnotherMethod();
 }
}

I read that an iterator was a pointer to the content of the vector, why
doesn't it work?


Thanks,


Renan M Z Mendes
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org