In: Computer Science
// 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;
}
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...