Sign in to follow this  
Ben091986

basic template question - access to std::vector

Recommended Posts

Ben091986    108
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[i].pos;
        pPointVertices->color = particleStore[i].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
ToohrVyk    1595
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
SiCrane    11839
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this