Hi,
I've an array in a class declered in the following way:
char pippo[256];
In the constructor of the class I would like to fill this array, but I
received an error.
Why?
tnx 21 1511
Salvatore Di Fazio wrote:
I've an array in a class declered in the following way:
char pippo[256];
In the constructor of the class I would like to fill this array, but I
received an error.
Why?
Most likely, because you write some incorrect code.
--
Salu2
Salvatore Di Fazio wrote:
Hi,
I've an array in a class declered in the following way:
char pippo[256];
In the constructor of the class I would like to fill this array, but I
received an error.
Why?
tnx
The error is on line 42.
well, here is one way you do it....
class Foo
{
private:
char pippo[256];
public:
Foo();
};
void main()
{
Foo A;
}
Foo::Foo()
{
//constructor is called when you declared the object in main and is
usued to initalize private member variable in your class
for(int i = 0; pippo[i]; i++)
{ pippo[i] = '0'; }
}
--You might want to write more code in the main portion of your program
to "fill" the array. This program only fills it with 0's. Hope that
helps!
Salvatore Di Fazio wrote:
Hi,
I've an array in a class declered in the following way:
char pippo[256];
In the constructor of the class I would like to fill this array, but I
received an error.
Why?
tnx
Salvatore Di Fazio wrote:
Hi,
I've an array in a class declered in the following way:
char pippo[256];
In the constructor of the class I would like to fill this array, but I
received an error.
Show. Us. The. Code.
Brian
Show us the code!
Oh yea! for(i=0; pippo[i];i++) in my earlier program should be
for(i=0;i < 256;i++)
Oh yea,
uche wrote:
well, here is one way you do it....
class Foo
{
private:
char pippo[256];
public:
Foo();
};
void main()
{
Foo A;
}
Foo::Foo()
{
//constructor is called when you declared the object in main and is
usued to initalize private member variable in your class
for(int i = 0; pippo[i]; i++)
{ pippo[i] = '0'; }
}
--You might want to write more code in the main portion of your program
to "fill" the array. This program only fills it with 0's. Hope that
helps!
Salvatore Di Fazio wrote:
Hi,
I've an array in a class declered in the following way:
char pippo[256];
In the constructor of the class I would like to fill this array, but I
received an error.
Why?
tnx
uche,
Please don't top-post. Your responses should be placed below or
interleaved with what you are replying to [fixed].
uche <ur***********@hotmail.comwrote:
Salvatore Di Fazio wrote:
>Hi, I've an array in a class declered in the following way:
char pippo[256];
In the constructor of the class I would like to fill this array, but I received an error.
well, here is one way you do it....
class Foo
{
private:
char pippo[256];
public:
Foo();
};
void main()
main() always returns int.
{
Foo A;
}
Foo::Foo()
{
//constructor is called when you declared the object in main and is
usued to initalize private member variable in your class
for(int i = 0; pippo[i]; i++)
The behavior of this program is undefined, since in the test condition
of your loop you access uninitialized memory (pippo[i]). Better would
be:
for (int i = 0; i < 256; ++i)
with the additional recommendation that the "magic number" 256 should be
replaced by a constant.
{ pippo[i] = '0'; }
Depending on what the OP is using it for, this may be acceptable, though
I would prefer
pippo[i] = '\0';
}
--You might want to write more code in the main portion of your program
to "fill" the array. This program only fills it with 0's. Hope that
helps!
--
Marcus Kwok
Replace 'invalid' with 'net' to reply
Nothing to easy to do :>
class Lop
{
Lop();
char a[2];
};
Lop::Lop()
{
a [] = { 1, 2 };
}
Default User ha scritto:
Show. Us. The. Code.
Brian
Salvatore Di Fazio wrote:
Default User ha scritto:
Show. Us. The. Code.
Nothing to easy to do :>
class Lop
{
Lop();
char a[2];
};
Lop::Lop()
{
a [] = { 1, 2 };
}
Please don't top-post, I have rearranged it.
You can't assign arrays. That's just the way it is. You can assign to
individual array members, so:
Lop::Lop()
{
a[0] = 1;
a[1] = 2;
}
Or:
Lop::Lop()
{
char b[sizeof a/sizeof a[0]] = {1,2};
memcpy(a, b, sizeof a);
}
Brian
Default User wrote:
Salvatore Di Fazio wrote:
>Default User ha scritto:
>>Show. Us. The. Code.
>Nothing to easy to do :>
class Lop { Lop();
char a[2]; };
Lop::Lop() { a [] = { 1, 2 }; }
Please don't top-post, I have rearranged it.
You can't assign arrays. That's just the way it is. You can assign to
individual array members, so:
Lop::Lop()
{
a[0] = 1;
a[1] = 2;
}
Or:
Lop::Lop()
{
char b[sizeof a/sizeof a[0]] = {1,2};
memcpy(a, b, sizeof a);
In an industrial program I'd prefer to see
static char b[sizeof a] = {1,2}; // since 'a' is of type char[]
// sizeof a[0] always yields 1
std::copy(b, b + sizeof b, a);
}
Brian
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Victor Bazarov posted:
> char b[sizeof a/sizeof a[0]] = {1,2};
memcpy(a, b, sizeof a);
In an industrial program I'd prefer to see
static char b[sizeof a] = {1,2}; // since 'a' is of type char[]
// sizeof a[0] always yields 1
std::copy(b, b + sizeof b, a);
One could easy argue the opposite side by stating that the former doesn't
break if the type of "a" is changed. Sort of like why people write:
memset( p, 0, sizeof *p );
instead of:
memset( p, 0, sizeof(SomeType) );
I myself would prefer the former form (in a slightly altered form albeit:
char b[sizeof a / sizeof *a];
--
Frederick Gotham
Okkey when I've just 2 elements.
But I've an array of 256 elements where it's filled by an algorithm
Default User wrote:
>
You can't assign arrays. That's just the way it is. You can assign to
individual array members, so:
Lop::Lop()
{
a[0] = 1;
a[1] = 2;
}
Or:
Lop::Lop()
{
char b[sizeof a/sizeof a[0]] = {1,2};
memcpy(a, b, sizeof a);
}
Brian
in this kind of condition, better
use fstream functions, open the text file
contains the algorithm, and import the algorithm into
the array, that's it.
Salvatore Di Fazio wrote:
Okkey when I've just 2 elements.
But I've an array of 256 elements where it's filled by an algorithm
Default User wrote:
You can't assign arrays. That's just the way it is. You can assign to
individual array members, so:
Lop::Lop()
{
a[0] = 1;
a[1] = 2;
}
Or:
Lop::Lop()
{
char b[sizeof a/sizeof a[0]] = {1,2};
memcpy(a, b, sizeof a);
}
Brian
check out the fstream file in your include document
or read c++ book about how to use c++ to operate on files.
Salvatore Di Fazio wrote:
Okkey when I've just 2 elements.
But I've an array of 256 elements where it's filled by an algorithm
Default User wrote:
You can't assign arrays. That's just the way it is. You can assign to
individual array members, so:
Lop::Lop()
{
a[0] = 1;
a[1] = 2;
}
Or:
Lop::Lop()
{
char b[sizeof a/sizeof a[0]] = {1,2};
memcpy(a, b, sizeof a);
}
Brian
* Salvatore Di Fazio:
[top-posting]
What part of "Please don't top-post" did you not understand?
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
* mike:
[top-posting on top of top-posting]
Please read the FAQ on how to post. Please don't top-post in this
group. Thank you.
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Victor Bazarov wrote:
Default User wrote:
char b[sizeof a/sizeof a[0]] = {1,2};
memcpy(a, b, sizeof a);
In an industrial program I'd prefer to see
static char b[sizeof a] = {1,2}; // since 'a' is of type char[]
// sizeof a[0] always yields 1
std::copy(b, b + sizeof b, a);
In an industrial program, I'd use something else altogether. For the
given problem, you're of course correct. It's slightly more robust to
leave it the way I have it in case someone changed the type, but not a
big deal.
Brian
Salvatore Di Fazio wrote:
Default User wrote:
You can't assign arrays. That's just the way it is. You can assign
to individual array members, so:
Lop::Lop()
{
a[0] = 1;
a[1] = 2;
}
Or:
Lop::Lop()
{
char b[sizeof a/sizeof a[0]] = {1,2};
memcpy(a, b, sizeof a);
}
Okkey when I've just 2 elements.
But I've an array of 256 elements where it's filled by an algorithm
Please don't top-post, I have rearranged the text properly.
From now on, present the ACTUAL problem, not something like the
problem. How can we suggest a solution when you hide the details?
Please note that the second version I have there isn't reliant on the
size.
Brian
Alf P. Steinbach wrote:
* Salvatore Di Fazio:
[top-posting]
What part of "Please don't top-post" did you not understand?
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
What means "Top-posting"
Salvatore Di Fazio <sa***************@gmail.comwrote:
>
Alf P. Steinbach wrote:
>* Salvatore Di Fazio:
> [top-posting]
What part of "Please don't top-post" did you not understand?
-- A: Because it messes up the order in which people normally read text. Q: Why is it such a bad thing? A: Top-posting. Q: What is the most annoying thing on usenet and in e-mail?
What means "Top-posting"
http://en.wikipedia.org/wiki/Top-posting
--
Marcus Kwok
Replace 'invalid' with 'net' to reply This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: its me |
last post by:
Let's say I have a class of people...
Public Class People
Public Sex as String
Public Age as int
Public Name as string
end class
And I declare an array of this class...
|
by: Buddy Ackerman |
last post by:
I created a simple class:
Public Class MyTestClass
Public Test() As String
End Class
I tried to assign some values to the array Test() and display them like this:
|
by: Gianni Mariani |
last post by:
Does anyone know if this is supposed to work ?
template <unsigned N>
int strn( const char str )
{
return N;
}
#include <iostream>
|
by: michi |
last post by:
Hello,
I need to initialize a 2 dimensional square arrays of structures. The size of array I get from the user. I can
do one-dimensional array, but I don't know how to specify the size of array...
|
by: justanotherguy63 |
last post by:
Hi,
I am designing an application where to preserve the hierachy and for
code substitability, I need to pass an array of derived class object in
place of an array of base class object. Since I...
|
by: Rade |
last post by:
Please have a look at the following program:
#include <iostream>
template <const int array, size_t index>
class ArrayIndex
{
public:
static const int value = array;
};
|
by: Armand |
last post by:
Hi Guys,
I have a set of array that I would like to clear and empty out.
Since I am using "Array" not "ArrayList", I have been struggling in
finding the solution which is a simple prob for those...
|
by: sandy |
last post by:
I need (okay, I want) to make a dynamic array of my class 'Directory',
within my class Directory (Can you already smell disaster?)
Each Directory can have subdirectories so I thought to put these...
|
by: =?Utf-8?B?U2hhcm9u?= |
last post by:
Hi Gurus,
I need to transfer a jagged array of byte by reference to unmanaged
function, The unmanaged code should changed the values of the array, and when
the unmanaged function returns I need...
|
by: npankey |
last post by:
I've started experimenting with template metaprogramming in a small
project of mine. What I'm trying to accomplish is to generate a static
array of templated objects that get specialized based on...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |