How to use dynamic bitset as member data of class?

Hello again, I enjoy to use the dynamic_bitset for the 1 bit correlation of radio interferometor. Very useful. But how to use the dynamic bitsets as the member data of the class? class multi_bitsets{ const boost::dynamic_bitset<> db1(20,1ul); const boost::dynamic_bitset<> db2(20,1ul); this kind of code always gives me the following errors: $ g++ multi_bitset_test00.cpp multi_bitset_test00.cpp:19: error: expected identifier before numeric constant multi_bitset_test00.cpp:19: error: expected `,' or `...' before numeric constant multi_bitset_test00.cpp:19: error: ISO C++ forbids declaration of `parameter' with no type Please let me know how to use the dynamic bitsets as the member data of the class, thank you. fuji

use the initializer list to call their constructors instead: multi_bitsets() : db1(20,1ul), db2(20,1ul) { } On 9/2/05, Fujinobu Takahashi <fjtaka@ynu.ac.jp> wrote:
Hello again,
I enjoy to use the dynamic_bitset for the 1 bit correlation of radio interferometor. Very useful.
But how to use the dynamic bitsets as the member data of the class?
class multi_bitsets{ const boost::dynamic_bitset<> db1(20,1ul); const boost::dynamic_bitset<> db2(20,1ul);
this kind of code always gives me the following errors:
$ g++ multi_bitset_test00.cpp multi_bitset_test00.cpp:19: error: expected identifier before numeric constant multi_bitset_test00.cpp:19: error: expected `,' or `...' before numeric constant multi_bitset_test00.cpp:19: error: ISO C++ forbids declaration of `parameter' with no type
Please let me know how to use the dynamic bitsets as the member data of the class, thank you.
fuji
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
-- Cory Nelson http://www.int64.org

Hello Cory-san, Thank you for your prompt advice for my basic question.
use the initializer list to call their constructors instead:
multi_bitsets() : db1(20,1ul), db2(20,1ul) { }
I tried and the result is as follows: $ g++ multi_bitset_test00.cpp multi_bitset_test00.cpp:38: error: expected unqualified-id before ')' token multi_bitset_test00.cpp:38: error: expected `,' or `;' before ':' token I am very helpful to gett any comments or solution for the error. Very thanks, Fuji On Sat, 3 Sep 2005 00:17:43 -0700 Cory Nelson <phrosty@gmail.com> wrote:
use the initializer list to call their constructors instead:
multi_bitsets() : db1(20,1ul), db2(20,1ul) { }
On 9/2/05, Fujinobu Takahashi <fjtaka@ynu.ac.jp> wrote:
Hello again,
I enjoy to use the dynamic_bitset for the 1 bit correlation of radio interferometor. Very useful.
But how to use the dynamic bitsets as the member data of the class?
class multi_bitsets{ const boost::dynamic_bitset<> db1(20,1ul); const boost::dynamic_bitset<> db2(20,1ul);
this kind of code always gives me the following errors:
$ g++ multi_bitset_test00.cpp multi_bitset_test00.cpp:19: error: expected identifier before numeric constant multi_bitset_test00.cpp:19: error: expected `,' or `...' before numeric constant multi_bitset_test00.cpp:19: error: ISO C++ forbids declaration of `parameter' with no type
Please let me know how to use the dynamic bitsets as the member data of the class, thank you.
fuji
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
-- Cory Nelson http://www.int64.org

Hello Cory-san, Thank you for your prompt advice for my basic question. I found same thing happens even when I use dynamic bitsets as member of struct. My original simple code: #include <iostream> #include <boost/timer.hpp> #include <boost/dynamic_bitset.hpp> using namespace std; using namespace boost; struct multi_bitsets{ dynamic_bitset<> db1(10,1ul); dynamic_bitset<> db2(10,2ul); }; int main() { multi_bitsets mb1; cout<<"mb1.db1:"<<mb1.db1<<endl; cout<<"mb1.db2:"<<mb1.db2<<endl; return 0; } Long error.log: $ g++ multi_bitset_struct.org.cpp multi_bitset_struct.org.cpp:9: error: expected identifier before numeric constant multi_bitset_struct.org.cpp:9: error: expected `,' or `...' before numeric constant multi_bitset_struct.org.cpp:9: error: ISO C++ forbids declaration of `parameter' with no type multi_bitset_struct.org.cpp:10: error: expected identifier before numeric constant multi_bitset_struct.org.cpp:10: error: expected `,' or `...' before numeric constant multi_bitset_struct.org.cpp:10: error: ISO C++ forbids declaration of `parameter' with no type multi_bitset_struct.org.cpp: In function `int main()': multi_bitset_struct.org.cpp:19: error: no match for 'operator<<' in 'std::operator<< [with _Traits = std::char_traits<char>](((std::basic_ostream<char, std::cha r_traits<char> >&)(&std::cout)), ((const char*)"mb1.db1:")) << mb1.multi_bitsets::db1' /usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/bits/ostream.tcc:63: note: candidates are: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits
::operator<<(std::basic_ostream<_CharT, _Traits>&(*)(std::basic_ostream<_CharT, _Traits>&)) [with _CharT = char, _Traits = std::char_traits<char>] /usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/bits/ostream.tcc:74: note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(s td::basic_ios<_CharT, _Traits>&(*)(std::basic_ios<_CharT, _Traits>&)) [with _CharT = char, _Traits = std::char_traits<char>] /usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/bits/ostream.tcc:86: note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(s td::ios_base&(*)(std::ios_base&)) [with _CharT = char, _Traits = std::char_traits<char>]
And modified code with the initializer list suggested by Cory-san: #include <iostream> #include <boost/timer.hpp> #include <boost/dynamic_bitset.hpp> using namespace std; using namespace boost; struct multi_bitsets{ dynamic_bitset<> db1; dynamic_bitset<> db2; }; multi_bitsets():db1(10,1ul), db2(10,2ul){} int main() { multi_bitsets mb1; cout<<"mb1.db1:"<<mb1.db1<<endl; cout<<"mb1.db2:"<<mb1.db2<<endl; return 0; } Very simple error code: $ g++ multi_bitset_struct.cpp multi_bitset_struct.cpp:14: error: expected unqualified-id before ')' token multi_bitset_struct.cpp:14: error: expected `,' or `;' before ':' token I am very helpful to gett any comments or solution for the error. Very thanks, Fuji

On 9/3/05 9:56 AM, "Fujinobu Takahashi" <fjtaka@ynu.ac.jp> wrote:
Hello Cory-san,
Thank you for your prompt advice for my basic question. I found same thing happens even when I use dynamic bitsets as member of struct.
I think you need to review your C++ syntax.
My original simple code: [SNIP] struct multi_bitsets{ dynamic_bitset<> db1(10,1ul); dynamic_bitset<> db2(10,2ul); }; [SNIP] multi_bitset_struct.org.cpp:9: error: expected identifier before numeric constant multi_bitset_struct.org.cpp:9: error: expected `,' or `...' before numeric constant multi_bitset_struct.org.cpp:9: error: ISO C++ forbids declaration of `parameter' with no type multi_bitset_struct.org.cpp:10: error: expected identifier before numeric constant multi_bitset_struct.org.cpp:10: error: expected `,' or `...' before numeric constant multi_bitset_struct.org.cpp:10: error: ISO C++ forbids declaration of `parameter' with no type [SNIP]
You can never initialize members of a struct/class in that fashion. You must use constructors: class multi_bitsets { public: multi_bitsets() : db1(10, 1ul), db2(10, 2ul) {} //... private: dynamic_bitset<> db1, db2; } Or you can initialize a simple struct/class at declaration time: struct test1 { int a, b }; //... int main() { test1 x = { 1, 4 }; //... } I forgot what restrictions, if any, are on that feature. If a class member is of static storage and of a built-in integral type, then you can do: class test2 { static unsigned const xx = 2u; //... } //... unsigned const test2::xx; // You still must do this! (I forgot if it works on "enum" too.)
------------------------------------------------------------------- And modified code with the initializer list suggested by Cory-san: [SNIP] struct multi_bitsets{ dynamic_bitset<> db1; dynamic_bitset<> db2; }; multi_bitsets():db1(10,1ul), db2(10,2ul){} [SNIP] multi_bitset_struct.cpp:14: error: expected unqualified-id before ')' token multi_bitset_struct.cpp:14: error: expected `,' or `;' before ':' token
Not modified enough. All members of a class must be declared in the class body, during or before a definition (if any). You cannot define an impromptu constructor (i.e. with no prior declaration). -- Daryle Walker Mac, Internet, and Video Game Junkie darylew AT hotmail DOT com

Hello Daryle-san,
I think you need to review your C++ syntax. I sincerely agree and will study C++ again.
I think multi-bitsets class by C++ will be a great breakthrough for radio interferometry correlation software. Very thanks your suggestion. Fuji On Sat, 03 Sep 2005 18:48:20 -0400 Daryle Walker <darylew@hotmail.com> wrote:
On 9/3/05 9:56 AM, "Fujinobu Takahashi" <fjtaka@ynu.ac.jp> wrote:
Hello Cory-san,
Thank you for your prompt advice for my basic question. I found same thing happens even when I use dynamic bitsets as member of struct.
I think you need to review your C++ syntax.
participants (3)
-
Cory Nelson
-
Daryle Walker
-
Fujinobu Takahashi