Question

In: Computer Science

// I can't get my cpp file to work with my header file and it always...

// I can't get my cpp file to work with my header file and it always says the error comes from compatibility I am using Visual Studio 2015 below is the error only my file path and program name has been erased. The issue comes up in my cpp file with the size_t empty and full functions.

// Error (active)       declaration is incompatible with "bool ListType::empty()" (declared at line 12 of ListType.h)        

// ListType header file

#ifndef ListType__h
#define ListType__h
#include
class ListType {
public:
   ListType();
   bool insert(int value);
   void eraseAll();
   void erase(int);
   bool find(int );
   size_t size();
   bool empty();
   bool full();
   const ListType & operator = (const ListType &other);
   friend std :: ostream & operator << (std :: ostream &out, const ListType &list);
protected:
   int list[100];
   size_t capacity;
   size_t count;
private:
};
#endif /* ListType__h */

//my cpp file

#include "ListType.h"
#include

ListType::ListType() {
   capacity = 100;
   count = 0;
}

bool ListType::insert(int value)
{
   bool result = false;
   if (!full()) {
       list[count] = value;
       ++count;
       result = true;

   }
   return result;
}

void ListType::eraseAll() {
   count = 0;
}
void ListType::erase(int value) {
   size_t i = 0;
   while (i < count&&value != list[i])++i;
   if (i < count) {
       list[i] = list[--count];
   }

}

bool ListType::find(int value) {
   bool result = false;
   if (!empty()) {
       size_t i = 0;
       while (i        result = (i    }
   return result;
}


size_t ListType::size() {
   return count;
}
size_t ListType::empty() {
   return count = 0;
}
size_t ListType::full() {
   return count == capacity;
}

const ListType& ListType:: operator=(const ListType& source) {
   if (this != &source) {
       count = source.count;
       for (size_t i = 0; i            list[i] = source.list[i];
       }
   }
   return *this;
}
std::ostream& operator<<(std::ostream &out, const ListType &other)

{

   out << "[ ";

   for (unsigned int i = 0;i

   {

       out << other.list[i] << " ";

   }

   out << "]";

   return out;

}

Solutions

Expert Solution

If you have any doubts, please give me comment...

ListType.h

// ListType header file

#ifndef ListType__h

#define ListType__h

#include<iostream>

class ListType

{

public:

    ListType();

    bool insert(int value);

    void eraseAll();

    void erase(int);

    bool find(int);

    size_t size();

    bool empty();

    bool full();

    const ListType &operator=(const ListType &other);

    friend std ::ostream &operator<<(std ::ostream &out, const ListType &list);

protected:

    int list[100];

    size_t capacity;

    size_t count;

private:

};

#endif /* ListType__h */

ListType.cpp

#include "ListType.h"

#include <iostream>

ListType::ListType()

{

    capacity = 100;

    count = 0;

}

bool ListType::insert(int value)

{

    bool result = false;

    if (!full())

    {

        list[count] = value;

        ++count;

        result = true;

    }

    return result;

}

void ListType::eraseAll()

{

    count = 0;

}

void ListType::erase(int value)

{

    size_t i = 0;

    while (i < count && value != list[i])

        ++i;

    if (i < count)

    {

        list[i] = list[--count];

    }

}

bool ListType::find(int value)

{

    bool result = false;

    if (!empty())

    {

        size_t i = 0;

        while (i < count)

        {

            if (list[i] == value)

                result = true;

            i++;

        }

    }

    return result;

}

size_t ListType::size()

{

    return count;

}

bool ListType::empty()

{

    return count == 0;

}

bool ListType::full()

{

    return count == capacity;

}

const ListType &ListType::operator=(const ListType &source)

{

    if (this != &source)

    {

        count = source.count;

        for (size_t i = 0; i < count; i++)

        {

            list[i] = source.list[i];

        }

    }

    return *this;

}

std::ostream &operator<<(std::ostream &out, const ListType &other)

{

    out << "[ ";

    for (unsigned int i = 0; i < other.count; i++)

    {

        out << other.list[i] << " ";

    }

    out << "]";

    return out;

}

The errors returned because of return datatype doesn't matched .cpp with .h file.. Here I modified everything it works fine...


Related Solutions

Using C++ Create the UML, the header, the cpp, and the test file for an ArtWork...
Using C++ Create the UML, the header, the cpp, and the test file for an ArtWork class. The features of an ArtWork are: Artist name (e.g. Vincent vanGogh or Stan Getz) Medium (e.g. oil painting or music composition) Name of piece (e.g. Starry Night or Late night blues) Year (e.g. 1837 or 1958)
I can't seem to make my inheritance to work properly between my parent class GameCharacter and...
I can't seem to make my inheritance to work properly between my parent class GameCharacter and the child classes hero and villain. Here's my code: import java.sql.SQLOutput; public class Main { public static void main(String[] args) { GameCharacter me = new GameCharacter("King Arthur", 5); GameCharacter tree = new GameCharacter("Tall Tree", 5); GameCharacter enemy = new GameCharacter("Monster Bug", 10); System.out.println(); System.out.println("\n~~~ Game Characters Created ~~~"); System.out.println(tree); System.out.println(me); System.out.println(enemy); System.out.println("\n~~~ The Bug Has Been Attacked ~~~"); me.attack(enemy); System.out.println(tree); System.out.println(me); System.out.println(enemy); System.out.println("\n~~~ The...
I can't get the number of days to print. Here is my code: public static void...
I can't get the number of days to print. Here is my code: public static void main(String[] args) { // Prompt the user to enter year Scanner scanner = new Scanner(System.in); // Prompt the user to enter year System.out.print("Enter full year (e.g., 2016): "); int year = scanner.nextInt(); for(int i = 1; i <= 12; i++) printMonth(year, i); } /** Print the calendar for a month in a year */ static void printMonth(int year, int month) { // Print the...
Debug the pet.h file and pet.cpp file (I would like to check my work) #ifnotdef PET_H...
Debug the pet.h file and pet.cpp file (I would like to check my work) #ifnotdef PET_H #then_define PET_H #include <string> using name space std namespace fhsuzeng { Class Pet { public Pet(); void setName(string name); string getName() const; void setAge(double age); int getAge() const; virtual void talk(); private: string _name; int _age; }; class Dog::public Pet { public: Dog(); void setBreed(string breed); string getBreed() const; private: string _breed; } class Cat:Pet { Public: Cat(); void setColor(string color); string getColor() const;...
I am struggling with this assignment. I can't get the program to run when I enter...
I am struggling with this assignment. I can't get the program to run when I enter a number with the $ symbol followed by a number below 10. any help would be greatly appreciated. Create a program named Auction that allows a user to enter an amount bid on an online auction item. Include three overloaded methods that accept an int, double, or string bid. Each method should display the bid and indicate whether it is over the minimum acceptable...
INTERPRETING THE REAL LIFE STORY: Karen’s Experience I always disliked how my skin would get pale...
INTERPRETING THE REAL LIFE STORY: Karen’s Experience I always disliked how my skin would get pale in the winter because I know I looked better with a tan. During the summer, my friends and I would lie out by the pool in our bathing suits. We wouldn’t even mind if we got a little sunburned, because we would just say “the burn will turn into a tan!” Before our senior prom, we all went to the tanning salon and used...
I can't understand the difference between 'the work the electric force does' and 'the work the...
I can't understand the difference between 'the work the electric force does' and 'the work the electric field does'. Could you explain it in detail?
answer in c++ First – take your Box02.cpp file and rename the file Box03.cpp Did you...
answer in c++ First – take your Box02.cpp file and rename the file Box03.cpp Did you ever wonder how an object gets instantiated (created)? What really happens when you coded Box b1; or Date d1; or Coord c1; I know you have lost sleep over this. So here is the answer………. When an object is created, a constructor is run that creates the data items, gets a copy of the methods, and may or may not initialize the data items....
My Java program keeps "running." I know I need to close a "loop" but I can't...
My Java program keeps "running." I know I need to close a "loop" but I can't find it. I'm learning how to code. This is confusing for me. import java.util.Scanner; import java.util.ArrayList; public class SteppingStone4_Loops {    public static void main(String[] args) { Scanner scnr = new Scanner(System.in); String recipeName = ""; ArrayList<String> ingredientList = new ArrayList(); String newIngredient = ""; boolean addMoreIngredients = true; System.out.println("Please enter the recipe name: "); recipeName = scnr.nextLine();    do {    System.out.println("Would you...
Below is my source code for file merging. when i run the code my merged file...
Below is my source code for file merging. when i run the code my merged file is blank and it never shows merging complete prompt. i dont see any errors or why my code would be causing this. i saved both files with male names and female names in the same location my source code is in as a rtf #include #include #include using namespace std; int main() { ifstream inFile1; ifstream inFile2; ofstream outFile1; int mClientNumber, fClientNumber; string mClientName;...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT