basic template question - access to std::vector

Started by
2 comments, last by Ben091986 16 years, 1 month ago
Hi folks, why does the compiler give me an error, when i try to do the following


template< typename particleStore >
void prtclRender::renderRender(particleStore)
{

    for( int i = 0; i < maxPart; i++ )
    {
        pPointVertices->posit = particleStore.pos;
        pPointVertices->color = particleStore.col;
        pPointVertices++;
    }
}
//...
//this is the call of that function 
renderRender(prtcl);
where prtcl is of type std::vector <STParticle> prtcl; pPointVertices & maxPart are some datamember. The version without templates has worked.

1>c:\documents and settings\ben\desktop\prometha\header\particle.h(332) : error C2275: 'particleStore' : illegal use of this type as an expression
1>        c:\documents and settings\ben\desktop\prometha\header\particle.h(155) : see declaration of 'particleStore'
1>        c:\documents and settings\ben\desktop\prometha\header\particle.h(155) : see reference to function template instantiation 'void prtclSys::prtclRender::renderRender<std::vector<_Ty>>(particleStore)' being compiled
1>        with
1>        [
1>            _Ty=prtclSys::STParticle,
1>            particleStore=std::vector<prtclSys::STParticle>
1>        ]
1>        c:\documents and settings\ben\desktop\prometha\header\particle.h(153) : while compiling class template member function 'const void prtclSys::CParticle<>::render(void)'
1>        c:\documents and settings\ben\desktop\prometha\header\scene3.h(118) : see reference to class template instantiation 'prtclSys::CParticle<>' being compiled
1>c:\documents and settings\ben\desktop\prometha\header\particle.h(332) : error C2228: left of '.pos' must have class/struct/union
1>c:\documents and settings\ben\desktop\prometha\header\particle.h(333) : error C2275: 'particleStore' : illegal use of this type as an expression
1>        c:\documents and settings\ben\desktop\prometha\header\particle.h(155) : see declaration of 'particleStore'
1>c:\documents and settings\ben\desktop\prometha\header\particle.h(333) : error C2228: left of '.col' must have class/struct/union

Advertisement
Quote:
error C2275: 'particleStore' : illegal use of this type as an expression

Quote:
template< typename particleStore >

pPointVertices->posit = particleStore.pos</u>;<br>pPointVertices-&gt;color = particleStore<u>.col</u>;<br><!–QUOTE–></td></tr></table></BLOCKQUOTE><!–/QUOTE–><!–ENDQUOTE–><br><br>The compiler error is perfectly clear: <i>particleStore</i> is a type, stop using it as if it were an expression.
You're trying to use particleStore as both the argument type and the name of the argument. This isn't valid. You probably want something like:
template< typename T >void prtclRender::renderRender(T particleStore)
thats it thank you very much

This topic is closed to new replies.

Advertisement