How to code this?

C

ccs

How to make a member function of a class take a type of std::bitset<N>, and
N is a variable that will be determined at run time? Thanks in advance!
 
J

John Harrison

ccs said:
How to make a member function of a class take a type of std::bitset<N>, and
N is a variable that will be determined at run time? Thanks in advance!

You cannot, template arguments must be determined at compile time.

Use vector<bool> instead of bitset<N>.

john
 
S

Sharad Kala

ccs said:
How to make a member function of a class take a type of std::bitset<N>, and
N is a variable that will be determined at run time? Thanks in advance!

Take a look at boost::Dynamic Bitset library.
 
C

ccs

Sharad Kala said:
Take a look at boost::Dynamic Bitset library.
Thanks for the tip!

How can a type of "vector<double>" or "valarray<double>" of dynamic size be
passed in a function as either reference or pointer?
 
S

Sharad Kala

ccs said:
Thanks for the tip!

How can a type of "vector<double>" or "valarray<double>" of dynamic size be
passed in a function as either reference or pointer?

Something like -
#include <iostream>
#include <vector>

void foo(std::vector<int>& v)
{
v.push_back(7);
v.push_back(8);
}

int main()
{
std::vector<int> vec;
vec.push_back(5);
foo(vec);
std::vector<int>::const_iterator itr;
for (itr = vec.begin(); itr != vec.end(); ++ itr)
std::cout << *itr; // print 578
}

-Sharad
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,170
Messages
2,570,925
Members
47,468
Latest member
Fannie44U3

Latest Threads

Top