Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

dawid

simple c++ q

This topic is 5192 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

is there a way to use a struct or class instead of saying struct.x =0 struct.y =0 struct.eg... i could say with struct do { x=0; y=0; eg....=0; } like in pascal

Share this post


Link to post
Share on other sites
Advertisement
No.


“Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.”
— Brian W. Kernighan (C programming language co-inventor)

Share this post


Link to post
Share on other sites
what about

class A{
public:
assign(int, int, int);
int x,y, eg;
};
A::assign(int xin, int yin, int egin){
x=xin;
y=yin;
eg=egin;
}

?

Share this post


Link to post
Share on other sites
huh?!! youll have to spell that out for me...
you initialize a function that takes in a struct and initializes it to whatever, and then call it whenever you want to assign members to the struct

Share this post


Link to post
Share on other sites
constructors, people.


struct MyStruct
{
MyStruct(int _a, int _b, int _c)
: a(_a), b(_b), c(_c)
{}

int a, b, c;
};

///then when you define a variable


MyStruct myVar(10, 11, 12);


i think thats what you want, right?[/source]

[edited by - silvermace on March 6, 2004 5:32:42 PM]

Share this post


Link to post
Share on other sites
is that what he wanted [ flabbergasted ] ??!!
since he was talking about external functions i assumed ...
huh... oh well

Share this post


Link to post
Share on other sites
You can get close with member functions, constructors... but there is no C++ equivalent to the Pascal & Basic 'with' construct.

dawid - on the other hand, if what you start with is a complex sequence of member accesses and other selection expressions, a reference may help you shorten things a bit:


foo[3].bar().baz->quux[12].blip.x = 5;
foo[3].bar().baz->quux[12].blip.y = 10;
foo[3].bar().baz->quux[12].blip.z = 20;

// could become

blip_type & ref = foo[3].bar().baz->quux[12].blip;
ref.x = 5;
ref.y = 10;
ref.z = 20;



“Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.”
— Brian W. Kernighan (C programming language co-inventor)


[edited by - Fruny on March 6, 2004 5:35:53 PM]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!