Search:
Forum
General C++ Programming
Nonconstant parameter for a template cla
Nonconstant parameter for a template class
Jun 23, 2011 at 3:23pm UTC
Pufo
(2)
I have a template class from an API that is instantiated with something like this.
BitField< length > object;
The problem is that length variable is only known at runtime.
error: 'length' cannot appear in a constant-expression -> this is the error message
Any suggestions ?
Jun 23, 2011 at 4:07pm UTC
Zhuge
(4664)
You can't do that. The compiler needs to generate templates at compile-time, as you can see. I would probably make that length parameter part of the constructor or something.
Jun 23, 2011 at 4:10pm UTC
kev82
(323)
Assuming a bitfield is array of bits, then I would suggest boost::dynamic_bitset<> as a replacement.
Topic archived. No new replies allowed.
C++
Information
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs