[RESOLVED] [C++11] - can avoid the class use the array operator?
imagine these simple class:
Code:
class test
{
public:
void write(string a)
{
cout << a;
}
};
(these class wasn't tested... it's for these question)
can avoid the class use the array operator('[]')?
Re: [C++11] - can avoid the class use the array operator?
Quote:
can avoid the class use the array operator('[]')?
Can you expand upon this so that we might have some idea as to what you are referring :confused:
Re: [C++11] - can avoid the class use the array operator?
Quote:
Originally Posted by
2kaud
Can you expand upon this so that we might have some idea as to what you are referring :confused:
imagine that label class that i'm doing... it's a control.
normaly you can do: label a[2];
can i avoid that? maybe doing the overloading empty?
Code:
void operator[](label &labelinstance)
{
//do nothing
}
i don't want use arrays with my class label
Re: [C++11] - can avoid the class use the array operator?
No.
Quote:
Originally Posted by
Cambalinho
i don't want use arrays with my class label
But what if I want to use it in arrays? What if I have 25 labels, and I want to supply some sort of attribute to each one? Are you saying I must create 25 separate variables??
Regards,
Paul McKenzie
Re: [C++11] - can avoid the class use the array operator?
Quote:
Originally Posted by
Paul McKenzie
No.But what if I want to use it in arrays? What if I have 25 labels, and I want to supply some sort of attribute to each one? Are you saying I must create 25 separate variables??
Regards,
Paul McKenzie
i get your point ;)
seems that i must see what i can do for arrays ;)
thanks for all
Re: [RESOLVED] [C++11] - can avoid the class use the array operator?
Sorry for the off-topic, dear Cambalinho, but in the most of the threads you started you look like (for me!) an inventor of perpetual motion machine. :rolleyes:
Re: [RESOLVED] [C++11] - can avoid the class use the array operator?
Quote:
Originally Posted by
VictorN
Sorry for the off-topic, dear Cambalinho, but in the most of the threads you started you look like (for me!) an inventor of perpetual motion machine. :rolleyes:
lol maybe sometimes.... lol
but i need some help, i don't know everything... the books never tell us everything.
but honestly i must say thanks to all, inclued you, for try help me so much. and i have a big thanks to 2kaud, he help me more than my thanks ;)
i start C++ by me and not by school(only Turbo Pascal and then i found that i love programming). but i have found that C++ can be more easy than locks. maybe you ask: why so many libraries? then i answer: why boost? what i mean is that i can share my libraries without a problems and will be great even for win32(VictorN i'm doing again... sorry).
it's a hobbie, but i love it and help me very in psicologic way(like music) ;)
thanks to all
Re: [C++11] - can avoid the class use the array operator?
Quote:
Originally Posted by
Cambalinho
imagine that label class that i'm doing... it's a control.
normaly you can do: label a[2];
can i avoid that? maybe doing the overloading empty?
if you make a class like
Code:
class label
{
// more stuff here
};
then you cannot prevent someone from doing
label a,b; // create 2 label objects
or
label a[2]; // create 2 label objects (which happen to be in an array, but the label class doesn't know this)
you can make the constructor private which would prevent any instantiation other than instantiation inside the class members itself. This is the technique behind a "singleton" (a design pattern than allows you to create only a single instance of a particular class). Is that what you're after ?