Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > C/C++
You last visited: Today at 00:27

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



boolean array in struct - help

Discussion on boolean array in struct - help within the C/C++ forum part of the Coders Den category.

Reply
 
Old   #1
 
elite*gold: 0
Join Date: Apr 2012
Posts: 372
Received Thanks: 21
boolean array in struct - help

Well, i have a struct with an boolean array in it... like this:

Code:
struct abc{
      bool mnzc[MAX];
};
how can i declare MAX? Because if i do it, jut like "int MAX=12;" it wont work...
Hikarim is offline  
Old 06/01/2013, 10:00   #2
 
ernilos's Avatar
 
elite*gold: 20
Join Date: Jan 2012
Posts: 766
Received Thanks: 645
#define MAX 12
ernilos is offline  
Old 06/01/2013, 10:35   #3


 
MrSm!th's Avatar
 
elite*gold: 7110
Join Date: Jun 2009
Posts: 28,902
Received Thanks: 25,407
^no
const int MAX = 12;
MrSm!th is offline  
Old 06/01/2013, 10:59   #4
 
TIMΣ™'s Avatar
 
elite*gold: 23
Join Date: Oct 2010
Posts: 2,986
Received Thanks: 357
I would say too const int MAX = 12;
TIMΣ™ is offline  
Old 06/01/2013, 14:15   #5


 
MrSm!th's Avatar
 
elite*gold: 7110
Join Date: Jun 2009
Posts: 28,902
Received Thanks: 25,407
btw. if it's not absolutely necessary to use an array (because a C function expects it as an argument or whatever), just use std::vector<bool>. It is even optimized to store the values in bits instead of bytes.
MrSm!th is offline  
Old 06/01/2013, 14:19   #6
 
Schlüsselbein's Avatar
 
elite*gold: 0
Join Date: Feb 2013
Posts: 1,137
Received Thanks: 869
vector<bool> sucks imho. Its no STL-container and it doesnt hold bools. If you want a bitst use std::bitest if you want an array of bools use std::deque<bool>.
Schlüsselbein is offline  
Old 06/01/2013, 16:32   #7


 
MrSm!th's Avatar
 
elite*gold: 7110
Join Date: Jun 2009
Posts: 28,902
Received Thanks: 25,407
Quote:
Its no STL-container
But? oO

Quote:
and it doesnt hold bools
saw that as an advantage. the inner representation shouldn't matter in most cases as you know. that's what oop is about
MrSm!th is offline  
Old 06/02/2013, 02:16   #8
 
Schlüsselbein's Avatar
 
elite*gold: 0
Join Date: Feb 2013
Posts: 1,137
Received Thanks: 869
Quote:
But? oO
But anything else. Take a look right here (and at the following links):
Quote:
saw that as an advantage. the inner representation shouldn't matter in most cases as you know. that's what oop is about
Jep, it shouldn't matter. But in case of case of vector<bool> it does. Thath because vector<bool> is different to vector<T> (where T != bool).

Btw: I can explain later in more detail (now im ******* drunk)
Schlüsselbein is offline  
Thanks
1 User
Old 06/02/2013, 03:05   #9


 
MrSm!th's Avatar
 
elite*gold: 7110
Join Date: Jun 2009
Posts: 28,902
Received Thanks: 25,407
Well, I see, vector<T> is guaranteed to behave as a c-style array when it comes to addressing the data buffer (i.e. there is an internal array). But usually you wouldn't need to use it as a c-style array. And if you know that detail, I actually don't see why you would have to prefer bitset.

Anyway, how is it possible then to have a vector of bools, if vector<bool> is no STL container but automatically included in <vector>?
Sure, you can use other containers, but isn't that kinda dirty? Why didn't they think about a proper standard implementation then? If I want to have a vector<bool>, I want to have a vector<bool> and no dequeue<bool> :<
MrSm!th is offline  
Thanks
1 User
Old 06/02/2013, 12:43   #10
 
elite*gold: 0
Join Date: May 2012
Posts: 115
Received Thanks: 16
const int max 12:
gogolus3000 is offline  
Reply


Similar Threads Similar Threads
[Collecting] RDB Struct
05/10/2013 - Rappelz Private Server - 7 Replies
hi every one , I have seen a lot of rdb struct but in different topics so i started this topic to collect all of them to help ppl that want to make a rdb tool or anything else and for all of the ppl how have rdb struct in there pc please share it with us :D
Struct Allokieren ?
12/08/2012 - C/C++ - 11 Replies
Hallo, Ich arbeite mich gerade durch das Buch C++ A - Z und bin gerade bei den Structuren, so jetzt habe ich mir als beispiel ein kleines (Telefon Buch) gemacht ganz simpel (Vorname, Nachname, Geschlecht, Nummer) Code #include "stdafx.h" using namespace std;
[Java&Sql]Boolean...
10/03/2012 - Web Development - 4 Replies
Hallo, ich habe einen Boolean in Java, welchen ich gerne in eine Sqltabele eintragen würde. In der Datenbank habe ich ein Feld mit dem Datentyp Tinyint erstellt... Wie kann ich mein Boolean am einfachsten in eine Zahl umwandeln und umgekehrt... einfach eintragen geht nicht, da bekomme ich folgende meldung: Incorrect integer value: 'false' for column 'SERVERREGION' at row 1
Java Boolean Frage
09/26/2012 - General Coding - 8 Replies
Ich möchte in meinem Java Code eine Boolean Abfrage einbauen, mein Problem dabei ist das bei der eingabe nur True oder False eingegeben werden kann, wie schreibe ich in Java das wenn ich z.B "ja" eingabe der boolean auf true gestellt wird. Dies ist relativ simpel da ich gerade erst mit Java begonnen habe jedoch finde ich es im Internet nicht. Danke für eure Hilfe.
[c++] struct
08/25/2011 - C/C++ - 2 Replies
Kann closed werden. sry



All times are GMT +1. The time now is 00:28.


Powered by vBulletin®
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2025 elitepvpers All Rights Reserved.