-
February 7th, 2014, 01:08 PM
#1
[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('[]')?
-
February 7th, 2014, 02:11 PM
#2
Re: [C++11] - can avoid the class use the array operator?
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
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
February 7th, 2014, 02:24 PM
#3
Re: [C++11] - can avoid the class use the array operator?
Originally Posted by 2kaud
Can you expand upon this so that we might have some idea as to what you are referring
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
-
February 7th, 2014, 02:55 PM
#4
Re: [C++11] - can avoid the class use the array operator?
No.
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
-
February 7th, 2014, 03:03 PM
#5
Re: [C++11] - can avoid the class use the array operator?
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
-
February 7th, 2014, 03:36 PM
#6
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.
Victor Nijegorodov
-
February 7th, 2014, 04:02 PM
#7
Re: [RESOLVED] [C++11] - can avoid the class use the array operator?
-
February 10th, 2014, 08:50 AM
#8
Re: [C++11] - can avoid the class use the array operator?
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 ?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|