Making Two Arrays Equal Each Other

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Serling1
    New Member
    • Mar 2008
    • 2

    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.

    Code:
    void Set::getData(Set& tempSet) const
    {
         for (int i = 0; i < size; i++)
    		tempSet[i] = set[i];
         
    }

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

    What am I doing wrong? Thanks for any help in advance.
  • oler1s
    Recognized Expert Contributor
    • Aug 2007
    • 671

    #2
    tempSet is not an array of type Set. What are you trying to achieve by indexing it?

    Comment

    • Serling1
      New Member
      • Mar 2008
      • 2

      #3
      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.

      Comment

      • weaknessforcats
        Recognized Expert Expert
        • Mar 2007
        • 9214

        #4
        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.

        Comment

        • fual
          New Member
          • Feb 2008
          • 28

          #5
          Originally posted by weaknessforcats
          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.

          Comment

          • kyleschlitt
            New Member
            • Feb 2008
            • 4

            #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?

            Comment

            • kyleschlitt
              New Member
              • Feb 2008
              • 4

              #7
              Originally posted by kyleschlitt
              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:

              Code:
              void Set::getData(Set& tempSet) const
              {
                for (int i = 0; i < size; i++)
                  tempSet.set[i] = set[i];
              }

              Comment

              • fual
                New Member
                • Feb 2008
                • 28

                #8
                Originally posted by kyleschlitt
                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) ;)

                Comment

                Working...