• Advertisement
Sign in to follow this  

basic template question - access to std::vector

This topic is 3622 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement
Quote:

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

Quote:

template< typename particleStore >

pPointVertices->posit = particleStore[ i ].pos;
pPointVertices->color = particleStore[ i ].col;


The compiler error is perfectly clear: particleStore is a type, stop using it as if it were an expression.

Share this post


Link to post
Share on other sites
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)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement