|
rec is a vector of some 150 structs each of which contain approx members of type char pointers. Before this function is called the vector is populated within another class and is never destroyed nor are the contents changed in any way.
Infact the add_list_item function is the only function in the program which has access to this vector.
|
|
|
|
|
Hi!
I am new to structures and I get how they work, sort of. And I have a question.
Let's say I've got this structure:
<br />
struct person<br />
{ string name;<br />
int eye_colour;<br />
float height;<br />
};<br />
<br />
person friend,mother;<br />
person spouse;<br />
Note that eye color is defined by a number. 1 is brown, 2 is blue, 3 is green and a NULL value is
an unknown eye color, or whatever you like.
So how can I make my program create a new person, which is user-inputted?
Something like this: ?
<br />
cin.get(newpersonname, 15)<br />
cin.ignore(16,'\n')<br />
create.person (newpersonname)<br />
And how would that work for structures within structures?
I'm kinda confused on this
thanks!
Peter
|
|
|
|
|
You cannot do that. What you have to do is read to several different members of your struct and supply them to your structure.
You can eventually go for operator overloading but I don't think in this case it is really appropriate.
|
|
|
|
|
Thank for the responses, guys, but everyone seems
to be worried about the eye color, which was
merely an example.
But if it's truly impossible to create "fields" or
"members" or whatever you call the things
like friend and mother and spouse in my
example, then my program is going to end
in tears, I'm afraid...
Well, thank, anyways!
|
|
|
|
|
Peter Charlesworth wrote: and a NULL value is
an unknown eye color, or whatever you like.
I would recommend using -1 instead of a NULL because NULL makes no sense with int ; or better, use an enum .
to answer your question try something like :
person mother;
mother.name = "Mom";
mother.eye_colour = 1;
mother.height = 1.34;
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
Thank for your answer but I was asking if it were possible
to create a new person whilst the program is running.
For instance, the user wishes to create a new person,
co-worker for instance, which uses the person structure.
Is it possible to create a new one without defining
it in the source code?
Thanks anyways!
|
|
|
|
|
struct person {
string name;
typedef enum {
BROWN = 1,
BLUE = 2,
GREEN = 3
} eyeColors_t;
eyeColors_t eye_colour;
float height;
friend istream& operator >> (const istream&, const person&);
};
istream& operator >> (istream& is, const person& p) {
is >> name >> eye_colour >> height;
return is;
}
|
|
|
|
|
Hmmm... that piece of code has given me an idea...
Thanks, V2.0 !
|
|
|
|
|
Define a constructor for your struct that takes name, eye_color and height as parameters (and has default values for all of them).
struct person
{
string name;
int eye_colour;
float height;
person(const string& n = "" , int e = -1 , float h = 0.0F);
};
person::person(const string& n, int e, float h)
: name(n), eye_color(e), height(h)
{}
Now you can create new instances of person easily:
person* spouse;
string newpersonname;
cin.get(newpersonname, 15);
cin.ignore(16,'\n');
spouse = new person(newpersonname);
|
|
|
|
|
Hmmm...
Does the second bit of code take 'spouse' as an example to make
'newpersonname' or does it erase 'spouse' in order to replace it
with 'newprersonname'?
Thanks anyways!
|
|
|
|
|
GetLogicalDriveStrings() can be used to get system driver stirngs in user mode app,if it can be used in driver program to do the same thing?
Thanks!
|
|
|
|
|
In my application i need to change brush attributes e.g color etc at run time,
consider following
CBrush b1;
b1.createSolidBrush(RGB(255,0,0));
now how can i change the color of same brushto green color?
An alternate option is to create new brush when it is needed and then destroy when its not, but this creation/destruction will slow down the prog, thats why i want to use only one brush and change its attributes as needed at run time
Thanks in advance
|
|
|
|
|
pc_dev wrote: An alternate option is to create new brush when it is needed
or create them both at the start of your app, and destroy them both at the end
Cleek | Image Toolkits | Thumbnail maker
|
|
|
|
|
hi Chris,
this has nothing to deal with the question you answered, but i wanted to know if you had received my mail, and if you have any particulier thoughts about it...
thanks,
v2.0
|
|
|
|
|
|
Thanks for reply.
Chris Losinger wrote:
create them both at the start of your app, and destroy them both at the end
If there were only two brushes needed then I would do the same but in my case i can't tell how much brushes will be needed, eg 1000.
in above case the best option is to create on eand change its attributes at run time.
|
|
|
|
|
pc_dev wrote: in above case the best option is to create on eand change its attributes at run tim
except that it's probably not possible to do that.
Cleek | Image Toolkits | Thumbnail maker
|
|
|
|
|
As far as I'm aware you don't - You create a new one.
Steve
|
|
|
|
|
Are you sure that creating/destroying the brush each time is that expensive? Try it and see how the program performs.
Software Zen: delete this;
|
|
|
|
|
Hi guys,
Can any one suggest me how i can write a very simple mouse hook?
suggest me some sample code.
Thanks,
Ram..
|
|
|
|
|
use SetWindowHookEx as follows
SetWindowsHookEx( WH_MOUSE, MouseProc,0,0);
u should write a function write a function(here "MouseProc") with prototype
LRESULT CALLBACK MouseProc( int nCode,
WPARAM wParam,
LPARAM lParam
);
Now u will get all the mouse messages in the function "MouseProc".
The above hook only works inside ur application scope. For u to make the hook globel u should have to write the "MouseProc" in a dll. and pass the instance(obtained from LoadLibrary) as the third parameter to the SetWindowsHookEx function.
nave
|
|
|
|
|
Hi Naveen,
Thanks..
As us said i am looking for a global mouse hook.
are there any rules for the dll like it should be a com outproc server or
is it enough to be ordinaly dll.
thanks and regards,
Ram
|
|
|
|
|
an ordinary dll is enough.
nave
|
|
|
|
|
Hello,
I'm using MS Visual Studio .NET 2003.
how can I get the total line count of the whole project?
Thanks in advance
|
|
|
|
|