CJCoding With Joseph
15free / daySign inCreate account

Seneca BTP 305

Debugging Template Class With Memory

Debugging Examples

The following Bucket code contains 7 errors. Find and fix them, then post in the community explaining what you found and how you fixed it.

Bucket.h

#ifndef BUCKET_H
#define BUCKET_H

#include <iostream>

template<typename T>
class Bucket {
    T value;

public:
    Bucket(int v = 0) {
        *this = v;
    }

    Bucket(Bucket& other) {
        value = other.value;
    }

    Bucket& operator=(const T& v) {
        value = v;
        return *this;
    }

    Bucket operator=(const Bucket& other) {
        value = other.value;
        return *this;
    }

    T get() {
        return value;
    }

    void set(T v) {
        value = v;
    }

    void reset() {
        value = 0;
    }

    bool equals(Bucket other) {
        return value == other.value;
    }

    void show() const {
        std::cout << value << std::endl;
    }
};

#endif
Members only

Keep reading this lesson

You've reached the end of the free preview. Unlock the rest of this lesson plus 17 more lessons in Seneca BTP 305.

  • Unlimited coding questions
  • Unlimited access to all classroom material
  • Weekly live call for questions and guidance
  • 3,000 AI tutor tokens / month
  • Personal SQL database (3 MB)
  • Progress tracking

Cancel any time.