Abbas Abbas - 2 months ago 9
C++ Question

syntax error: missing ',' before '<'

I just started coding in c++ after a long while, and perhaps I am missing something syntactically obvious here, but I have searched for good long while now and can't find a reference to my problem anywhere. I am trying to create a custom C++ class for

set
and
multiset
.

Here is my class cset.h

#pragma once
#include <set>
#include "cmultiset.h"

template <class Type>

class Set : public set<Type>
{
private:

public:
void add(Type &);
};


And here is my cmultiset.h

#pragma once
#include <set>

template <class Type>

class MultiSet : public multiset<Type>
{
private:

public:
bool operator < (MultiSet <Type> &);
};


What I am trying to do here is create a
Set<MultiSet<int>>
in my driver class. But get the following error twice for each file instead in the above header files at
class Set : public set<Type>
and
class MultiSet : public multiset<Type>
.

syntax error: missing ',' before '<'


I don't know how to resolve this error.

If I use just
set<MultiSet<int>>
everything works fine: No Errors no warnings (I do have to add
using namespace std;
before the template). However when I use
Set<MultiSet<int>>
it gives the error and
using namespace std
doesn't work.

Edit 1 :

Here is my github repository as requested.

Errors :

Severity Code Description Project File Line Suppression State
Error C2143 syntax error: missing ',' before '<' Integer Sets Analyzer c:\users\abbas\documents\mega\personal projects\integer sets analyzer\integer sets analyzer\cmultiset.h 6
Error C2143 syntax error: missing ',' before '<' Integer Sets Analyzer c:\users\abbas\documents\mega\personal projects\integer sets analyzer\integer sets analyzer\cmultiset.h 6
Error C2143 syntax error: missing ',' before '<' Integer Sets Analyzer c:\users\abbas\documents\mega\personal projects\integer sets analyzer\integer sets analyzer\cset.h 7
Error C2143 syntax error: missing ',' before '<' Integer Sets Analyzer c:\users\abbas\documents\mega\personal projects\integer sets analyzer\integer sets analyzer\cmultiset.h 6
Error C2143 syntax error: missing ',' before '<' Integer Sets Analyzer c:\users\abbas\documents\mega\personal projects\integer sets analyzer\integer sets analyzer\cset.h 7


Edit 2 :

Here is my main.cpp

#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <string>
#include <conio.h>
#include "cmultiset.h"
#include "cset.h"

using namespace std;

int main()
{
Set<MultiSet <int>> intSet;

intSet.clear();

_getch();

return 0;
}


Here is my MultiSet.cpp

#pragma once
#include "stdafx.h"
#include "cmultiset.h"

using namespace std;

template <class Type>
bool MultiSet<Type>::operator < (MultiSet<Type> & cmpSet)
{
if (this->size() < cmpSet.size())
{
return true;
}
else if (this->size() > cmpSet.size())
{
return false;
}

for (multiset<Type>::iterator it = this->begin(), jt = cmpSet.begin(); it != this->end(), jt != cmpSet.end(); ++it, ++jt)
{
if (*it < *jt)
return true;
}

return false;
}


Here is my Set.cpp.

#pragma once
#include "stdafx.h"
#include "cset.h"

using namespace std;

template <class Type>
void Set<Type> :: add(Type & entry)
{
set<Type>::insert(entry);
}

M.M M.M
Answer

In class Set : public set<Type>, it should be std::set instead of set.

The compiler gives a syntax error otherwise because it doesn't realize set is a class template.

There is a similar problem with multiset in the next part.

NB. Standard containers are not meant to be inherited from; consider using containment instead (i.e. have the container as a member variable).

Comments