0
votes

I have create this squareList class I when I compile it it give me to many errors I don't know can someone help me to resolve those error update: I comment all my code after ~square_list(){} and every error pinpoint to list data;

///#include "LinkedList.hpp"
#include <vector>
#include <cassert>
#include <iostream>
#include <iomanip>
#include <math.h>
#include <list>
#include <iterator>


template <typename T_>

class square_list
{

    typedef T_              value_type;
    typedef std::size_t     size_type;
    typedef T_ &            reference;
    typedef T_ const &      const_reference;
    typedef T_ *            pointer;
    typedef T_ const *      const_pointer;
    typedef T_ *            iterator;
    typedef T_ const *      const_iterator;
    typedef std::ptrdiff_t  difference_type;

    typedef std::reverse_iterator<iterator> reverse_iterator;
    typedef std::reverse_iterator<const_iterator> const_reverse_iterator;



     //for header vector<pair<itr,unsindINT) header
    list<T_> data;





    square_list() {}
    ~square_list(){}

 //   bool empty(){
    //  if(this->begin() == nullptr && this->end() == nullptr)
    //      return 1;
    //  else
    //      return 0;
    //}

    //list<value_type>::iterator    begin() {
    //  return data.begin(); 
    //}
    //list<value_type>::iterator    end() { 
    //  return data.end(); 
    //}
};

Error 1 error C2143: syntax error : missing ';' before '<'
Error 4 error C2143: syntax error : missing ';' before '<'
Error 7 error C2143: syntax error : missing ';' before '<'
Error 10 error C2143: syntax error : missing ';' before '<'
Error 13 error C2143: syntax error : missing ';' before '<'
Error 16 error C2143: syntax error : missing ';' before '<'
Error 19 error C2143: syntax error : missing ';' before '<'
Error 22 error C2143: syntax error : missing ';' before '<'
Error 25 error C2143: syntax error : missing ';' before '<'
Error 28 error C2143: syntax error : missing ';' before '<'
Error 31 error C2143: syntax error : missing ';' before '<'
Error 34 error C2143: syntax error : missing ';' before '<'
Error 37 error C2143: syntax error : missing ';' before '<'
Error 40 error C2143: syntax error : missing ';' before '<'
Error 43 error C2143: syntax error : missing ';' before '<'
Error 46 error C2143: syntax error : missing ';' before '<'
Error 3 error C2238: unexpected token(s) preceding ';' Error 6 error C2238: unexpected token(s) preceding ';' Error 9 error C2238: unexpected token(s) preceding ';' Error 12 error C2238: unexpected token(s) preceding ';' Error 15 error C2238: unexpected token(s) preceding ';' Error 18 error C2238: unexpected token(s) preceding ';' Error 21 error C2238: unexpected token(s) preceding ';'
Error 24 error C2238: unexpected token(s) preceding ';'
Error 27 error C2238: unexpected token(s) preceding ';'
Error 30 error C2238: unexpected token(s) preceding ';'
Error 33 error C2238: unexpected token(s) preceding ';'
Error 36 error C2238: unexpected token(s) preceding ';'
Error 39 error C2238: unexpected token(s) preceding ';'
Error 42 error C2238: unexpected token(s) preceding ';'
Error 45 error C2238: unexpected token(s) preceding ';'
Error 48 error C2238: unexpected token(s) preceding ';' Error 2 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int Error 5 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int Error 8 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int Error 11 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int Error 14 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int Error 17 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int Error 20 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int Error 23 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int Error 26 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int Error 29 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int Error 32 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int Error 35 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int Error 38 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int Error 41 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int Error 44 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int Error 47 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

4
The only issue I see is list<T> data which should be list<T> data. Other than that I see no other problem. Are you sure this code reproduces the errors shown?0x499602D2
yes it reproduces and no use?user474901
since you typedef T_ as value_type you should use value_type insteadmichaeltang

4 Answers

1
votes

it seems the compiler error is caused by the private construtor, this piece of code can compiler, hope it will help,

#include <vector>
#include <cassert>
#include <iostream>
#include <iomanip>
#include <math.h>
#include <list>
#include <iterator>
using namespace std;

#define nullptr NULL
template <typename T_>
class square_list
{
public:
    typedef T_              value_type;
    typedef std::size_t     size_type;
    typedef T_ &            reference;
    typedef T_ const &      const_reference;
    typedef T_ *            pointer;
    typedef T_ const *      const_pointer;
    typedef T_ *            iterator;
    typedef T_ const *      const_iterator;
    typedef std::ptrdiff_t  difference_type;

    typedef std::reverse_iterator<iterator> reverse_iterator;
    typedef std::reverse_iterator<const_iterator> const_reverse_iterator;



     //for header vector<pair<itr,unsindINT) header
    list<value_type> data;


    square_list() {}
    ~square_list(){}

    bool empty(){
        if(this->begin() == nullptr && this->end() == nullptr)
            return 1;
        else
            return 0;
    }

    /*list<T_>::iterator  begin() {
        return data.begin();
    }
    list<T_>::iterator  end() {
        return data.end();
    }*/
};


int main()
{
    square_list<int> sq_list;
    return 0;
}
0
votes

Your template parameter is T_, but you are referring to something called T which is undefined. Try changing

list<T> data<T>;

to

list<T_> data;

Also, try commenting out everything inside the class declaration and compiling. Then uncomment one line at a time and deal with any errors that appear after adding each line.

0
votes

The first problem is this line

list<T> data<T>;

it should be

list<T> data;

Those template arguments are unnecessary and syntactically invalid. Also, you haven't defined the template argument T. Did you mean T_ (or value_type rather)?

Also, you need typename in return types of your begin() and end() methods as value_type is a dependent type:

typename list<value_type>::iterator  begin();
typename list<value_type>::iterator  end();

You can even take advantage of return type deduction:

auto begin() -> decltype(data.begin());
auto end()   -> decltype(data.end());
0
votes
list<value_type> data;

The code's problem is lack of std:: as follows:

std::list<value_type> data;

You also write using namespace std; before the class definition.