|
You last visited: Today at 00:27
Advertisement
boolean array in struct - help
Discussion on boolean array in struct - help within the C/C++ forum part of the Coders Den category.
06/01/2013, 09:29
|
#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...
|
|
|
06/01/2013, 10:00
|
#2
|
elite*gold: 20
Join Date: Jan 2012
Posts: 766
Received Thanks: 645
|
#define MAX 12
|
|
|
06/01/2013, 10:35
|
#3
|
elite*gold: 7110
Join Date: Jun 2009
Posts: 28,902
Received Thanks: 25,407
|
^no
const int MAX = 12;
|
|
|
06/01/2013, 10:59
|
#4
|
elite*gold: 23
Join Date: Oct 2010
Posts: 2,986
Received Thanks: 357
|
I would say too const int MAX = 12;
|
|
|
06/01/2013, 14:15
|
#5
|
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.
|
|
|
06/01/2013, 14:19
|
#6
|
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>.
|
|
|
06/01/2013, 16:32
|
#7
|
elite*gold: 7110
Join Date: Jun 2009
Posts: 28,902
Received Thanks: 25,407
|
Quote:
But? oO
Quote:
saw that as an advantage. the inner representation shouldn't matter in most cases as you know. that's what oop is about
|
|
|
06/02/2013, 02:16
|
#8
|
elite*gold: 0
Join Date: Feb 2013
Posts: 1,137
Received Thanks: 869
|
Quote:
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)
|
|
|
06/02/2013, 03:05
|
#9
|
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> :<
|
|
|
06/02/2013, 12:43
|
#10
|
elite*gold: 0
Join Date: May 2012
Posts: 115
Received Thanks: 16
|
const int max 12:
|
|
|
 |
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.
|
|