Archived

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

craphead

symbolization

Recommended Posts

You would need a class and some overloaded operators, I think. Try to find a way around it for now.

If you really need an int to be several different numbers at once, you could try building a quantum computer.

Share this post


Link to post
Share on other sites
If you can think of a way to use such a variable that can''t be done better and simpler in another way, I''ll give you a cookie. What you''re asking can''t be done simply. Try to re-think your problem.

Share this post


Link to post
Share on other sites
Why exactly do you want to do this? There is probably a far better method for what you need.

And, as someone else mentioned, it probably wouldn''t be that difficult to create a class with that behavior, although I can''t imagine what you would need it for.

Share this post


Link to post
Share on other sites

    
class RangeNumber
{
public:
RangeNumber(int low, int high)
{
if(low > high)
throw "Error! Low bound must not be greater than high bound!";
this->low = low;
this->high = high;
}
bool operator==(int n)
{
return (n >= low && n <= high);
}
private:
int low;
int high;
};

Something like that ...

[edited by - Miserable on December 23, 2002 5:58:11 PM]

Share this post


Link to post
Share on other sites
What a useless class. I think it needs a = operator, and then it should be exactly what craphead wanted.

EDIT: Wait, never mind. A = operator would also be useless.

[edited by - micepick on December 23, 2002 6:04:27 PM]

Share this post


Link to post
Share on other sites
quote:
Original post by micepick
What a useless class. I think it needs a = operator, and then it should be exactly what craphead wanted.

I never claimed it''s useful - it''s not, but I think it''s something like what the OP wanted.

How would you write an operator=()? I don''t know how it could be made to take more than one parameter.

Share this post


Link to post
Share on other sites
All these post and no one has mentioned an array? And this is the beginner forum and you guys are talking about a class with overloaded operators? Shame on you all.



int a[90],j;
for(j=0;j<90;j++) a[j]=i+1;

// you can loop thru and access all
// the elements like this:

for(j=0;j<90;j++) printf("\n %d",a[j]);



[edited by - nonnus29 on December 23, 2002 9:53:41 PM]

Share this post


Link to post
Share on other sites
quote:
Original post by craphead
this is what i need but wont work

int y2;
y2>0 && y2<91;


Did you write it as ''if(y2>0 && y2<91);'' instead of ''if(y2>0 && y2<91)'', because that would make the if statement always appear to work, even if it shouldn''t.

Share this post


Link to post
Share on other sites
You don''t understand. He''s asking for an object that is all the values between 1 and 90:


  

range_int x;
x>0 && x<91; <---- bizarre syntax

if (x==5)
{
// this code executes

}

if (x==30)
{
// this code also executes

}



At least, that''s the impression I got.

Share this post


Link to post
Share on other sites