|
The Almighty MSDN says:
"When the sizeof operator is applied to a class, struct, or union type, the result is the number of bytes in an object of that type, plus any padding added to align members on word boundaries."
If I am not wrong sizeof should return in your case:
10 bytes, because a word is 2 byte. But it might be even more, depending on your system and how the padding is done.
int = 4 bytes
char = 1 byte
float = 4 bytes
total = 9 bytes + padding to word boundaries (1 byte here)
Tobias
|
|
|
|
|
it returns the size that the class/structure actually occupies in memory.
it can take 9 bytes (as you say) in minimum on a 32 bits machine ( (int = 4) + (char = 1) + (float = 4) ), but on a 64 bits system, your int will be 8 bits wide.
moreover, the compiler aligns the members on the larger member.... so, don't expect your struct to be 9 bytes wide.
|
|
|
|
|
I really really need help with tracking the mouse in a simple image program i am writing, any help will be greatly appresciated.
I have writen the program to load an image, and display its dimensions, which it does.
I now need to get it to alter the pixel values within a selection, i cant get the selection to display or select.please help
Be good...if you can't be good....be good at it!
|
|
|
|
|
how do you make a shared function?
In VB.NET I'd have done like this:
Public Shared Function f() As Integer
Think it's something like this:
public:<br />
int f()
but how do you make it shared?
|
|
|
|
|
As far as I know is the Shared keyword the equivalent to C#'s static keyword. Furthermore please note that the static keyword in VB is different to C#'s or C++/C one. However, static should be the way to go.
Tobias
|
|
|
|
|
|
Hello everybody,
I have two classes, one in c# and one in c++. The c# class is derived from the c++ class. Now I want to create a new virtual member function. No problem. But the function should return a double value in an parameter.
I use VS2005.
c#
public override Status GetProgress (ref System.Double dVal)
{
...
}
What's the equivalent of the base class in c++ ?
virtual Status GetProgress (System::Double ^dVal) is wrong.
Does anybody know the solution?
|
|
|
|
|
Probably you're looking for a "tracking reference %".
As far as i know it should be in your case :
virtual Status GetProgress (System::Double^% dVal)
On the other hand an interior pointer might suit as well;
virtual Status GetProgress (interior_ptr<System::Double> dVal)
Tobias
|
|
|
|
|
Hi Tobias,
thank you for the quick reply.
Using "System::Double^% dVal", I'm still getting an error message: no suitable method found to override. But "interior_ptr<system::double> dVal" works.
Now I'm checking, what it means...
Thanks!!
Hermann
|
|
|
|
|
// Assuming Status is a ref class
virtual Status^ GetProgress(System::Double% dVal) override
{
}
|
|
|
|
|
Hi George,
Thanks a lot! It works! Since I know it's a tracking reference, I found the description in the online help. Now I realized the meaning
Hermann
|
|
|
|
|
how to create an algorithm?
|
|
|
|
|
Simple,
int algorithm (int i) { return i; }
"Programming today is a race between software engineers striving to build bigger and
better idiot-proof programs, and the Universe trying to produce bigger and better idiots.
So far the Universe is winning." -- Rich Cook
|
|
|
|
|
this is not exactly an algorithm, as it refers to a programming language...
but as the question was a bit stupid, i second you in your answer
|
|
|
|
|
your question doesn't mean anything.
take in consideration this :
what do you want to achieve ?
what main steps do you have to go through ?
what technologies will you use ?
|
|
|
|
|
>your question doesn't mean anything.
If your a programmer it should!
An algorithm is just a list of
instructions detailing how to
do something. Could be making
a peanut butter and jelly
sandwich.
|
|
|
|
|
man, i know what an algorithm is
but still the question didn't mean anything...
what sort of algorithm was want ?
printing ?
3D rendering ?
Arccosine calculation ?
-- modified at 10:52 Tuesday 21st March, 2006
|
|
|
|
|
I didn't write the question nor
was I trying to insult you.
|
|
|
|
|
Is it possible that foxylady is referring to an STL Algorithm?
|
|
|
|
|
wow ehhmm, i really don't know, but now you say it, maybe !!
but 1) the question is really not clear, and 2) it is not the good forum for that, so i was far from thinking to STL algorithm...
|
|
|
|
|
I'm an infant when it comes to C++.
Can anybody help me to access a text file which has a comma that separates every item and after which put that file into an array which can be access later.
The problem is the items in a file are in this manner, each line:
char,int,int,int,long int,long int........
char,int,int,int,long int,long int........
char,int,int,int,long int,long int........
char,int,int,int,long int,long int........
........
.............
.........
......
upto 57-60 lines
Do i have to separate the char and int and long int and put it in different array?
Or put the items in a struct....
|
|
|
|
|
you can have struct array or array in struct.
|
|
|
|
|
Thanks a lot Saksida, i'll use struct array. you give me the hint that uncovers a mile area.
i'm currently studying how to do that.... at this website..
http://wps.aw.com/aw_savitch_abscpp_2s/0,10408,1982372-,00.html
there are few problems: this is the overview of my project, i mean a chunk of my project..
Actual items in the file M637.VIN
M2,2,1,15,55342,55662,55982,56302
A,4,1,15,58856,59176,59496,59816
P,5,1,15,55327,55647,55967
B,7,1,15,55310,55630,55950,56270
4B,8,2,15,27769,25530
General format:
char_val,int_val1,int_val2,int_val3,longint_val1
How am I suppose to say this…..
char_val = string or character
int_val1 = integer
int_val2 = integer
int_val3 = integer
longint_val(n) = an array of long integers
is it possible to store these stuff in a struct or an array of some sort? Coz i need int_val1 and int_val2 as a reference to an output port.
in line 1 "M2,2,1,15, 55342,55662,55982,56302" , i need to access the extracted input ‘2’ and ‘1’ coz it corresponds to an output port2 and port1.
on the other hand, char_val must be taken into account coz it serves as a reference to longint_val(n).
|
|
|
|
|
>>is it possible to store these stuff in a struct or an array of some sort?
just define your own structtype like the one below or use an odinary struct.
typedef struct
{
char* charval;
int intval1;
int intval2;
int intval3;
long* longintarray;
// if you know the length of your array at compile time then you could use
// long longintarray[n]; instead.
}tItem;
Read your data line by line from your file and create in a loop an instance of tItem for each line.
Fill it with data and add it to your array.
An implementation could look like this :
Please note that this is no valid code, it's just a little PSEUDOCODE representation.
define an array of tItem
while(!= end of file)
{
buffer = readoneline
tItem tmpStruct;
tmpStruct.charval = new char ( lenght of your read char(s))
tmpStruct.charval = copy the data from your buffer to the location where the pointer is pointing to // strcpy for instance
tmpStruct.intval1 = atoi(pointer to your buffer)
tmpStruct.intval2 = atoi(pointer to your buffer)
tmpStruct.intval3 = atoi(pointer to your buffer)
evaluate count of long int in the current line
tmpStruct.longintarray = new long (count of long int's);
pointertoyour buffer = a pointer on the first long;
for( int i = 0; i < count of long values; i++)
{
tmpStruct.longintarray = atol(pointertoyourbuffer)
tmpStruct.longintarray++;
pointertoyourbuffer++;
}
add the tmpStruct to your array of structs
}
have fun
Tobias
|
|
|
|
|
Kuroro Rucilful wrote: Do i have to separate the char and int and long int and put it in different array?
Or put the items in a struct....
This all depends on what you need them afterwards. If the char,int,long int,etc are all related then I would use a struct to group the info. If they have no relation, then I would use different array's.
Kuroro Rucilful wrote: Can anybody help me to access a text file which has a comma that separates every item and after which put that file into an array which can be access later.
Check out the fstream library. It has a function whereby you can read the file a line at a time (.getline I think). There are also C-runtime mechanisms to do a complete file read (using fread ).
regards,
Rich
"Programming today is a race between software engineers striving to build bigger and
better idiot-proof programs, and the Universe trying to produce bigger and better idiots.
So far the Universe is winning." -- Rich Cook
|
|
|
|
|