I defined a constructor of Bag class, but compiler gave me an error for the definition. I'm using CLion on Mac. I have no idea what is wrong. I'm thinking it's probably about CLion or compiler problem. Any help would be appreciated!
Here's the error message from compiler
/Users/username/Desktop/projects/bag/Bag.cpp:8:1: error: 'Bag' is not a class, namespace, or enumeration
Bag::Bag() : data{new T[CAPACITY]}, size{0} {}
^
/Users/username/Desktop/projects/bag/Bag.h:15:7: note: 'Bag' declared here
class Bag{
Here's declaration of Bag class which is in 'Bag.h' file.
#ifndef BAG_BAG_H
#define BAG_BAG_H
#include <vector>
#include <cstdlib>
using namespace std;
static const size_t CAPACITY = 100;
template <class T>
class Bag{
public:
Bag();
size_t size() const;
bool empty();
bool check(const T& item);
void resize(size_t new_size);
void clear();
void remove(const T& item);
void add(T item);
void print();
private:
T* data;
size_t _size;
};
#endif //BAG_BAG_H
Here's the definitions of Bag class which is in 'Bag.cpp' file.
#include "Bag.h"
template <class T>
Bag::Bag() : data{new T[CAPACITY]}, size{0} {}
... other definitions
Here's main.cpp
#include <iostream>
#include "Bag.h"
int main() {
Bag<int> temp();
temp().add(1);
temp().print();
cout << endl;
return 0;
}