468,491 Members | 2,038 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,491 developers. It's quick & easy.

Making Two Arrays Equal Each Other

I'm trying to have a getData function transfer all the objects it is holding in its array to a new array so that the new array can be used in a friend function to print the objects' information.

Expand|Select|Wrap|Line Numbers
  1. void Set::getData(Set& tempSet) const
  2. {
  3.      for (int i = 0; i < size; i++)
  4.         tempSet[i] = set[i];
  5.  
  6. }
  7.  

That code gives me this error: no match for 'operator[]' in 'tempSet[i]'

What am I doing wrong? Thanks for any help in advance.
Mar 16 '08 #1
7 11623
oler1s
671 Expert 512MB
tempSet is not an array of type Set. What are you trying to achieve by indexing it?
Mar 16 '08 #2
I'm trying to have the objects (Time objects) contained in the Set object given to another Set object. I have a function in my Time class that will print Time objects so I want to cycle through each Time object in the Set (which is an array) and print each one. To do this I need to get the objects using this getData function.
Mar 16 '08 #3
weaknessforcats
9,207 Expert Mod 8TB
Did you understand Post #2?

tempSet is a reference. That means one object. That means tempSet[i] is an error.

There is nothing in your function about Time objects.
Mar 17 '08 #4
fual
28
Did you understand Post #2?

tempSet is a reference. That means one object. That means tempSet[i] is an error.

There is nothing in your function about Time objects.
That is not necessarily true. It is a member function of Set and it would work perfectly well if Set::operator[](std::size_t) were overloaded (which is what the compiler is saying), and Set contained an array called set.
Mar 17 '08 #5
We would naturally assume that this is not the case based on what we have been shown.

Could the op please post the class header for class Set so we can properly identify the problem at hand?
Mar 17 '08 #6
We would naturally assume that this is not the case based on what we have been shown.

Could the op please post the class header for class Set so we can properly identify the problem at hand?
But my guess is that you want:

Expand|Select|Wrap|Line Numbers
  1. void Set::getData(Set& tempSet) const
  2. {
  3.   for (int i = 0; i < size; i++)
  4.     tempSet.set[i] = set[i];
  5. }
  6.  
Mar 17 '08 #7
fual
28
We would naturally assume that this is not the case based on what we have been shown.

Could the op please post the class header for class Set so we can properly identify the problem at hand?
When you say 'we,' one would naturally assume that you meant 'one' (unless you are the Queen of England, Your Majesty) ;)
Mar 17 '08 #8

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by M. Katz | last post: by
3 posts views Thread by Pablo Gomes Ludermir | last post: by
reply views Thread by Halvor Nyberg | last post: by
4 posts views Thread by Mark Healey | last post: by
14 posts views Thread by serge calderara | last post: by
1 post views Thread by reedr | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by theflame83 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.