C++ 解决C++;“我的列表”中的类模板错误
我已经创建了这个squareList类,当我编译它时,它会给我带来很多错误,我不知道有人能帮我解决这些错误吗 更新:我在~square_list(){}之后注释我的所有代码,并将每个错误精确定位到列表数据C++ 解决C++;“我的列表”中的类模板错误,c++,visual-c++,boost,c++11,C++,Visual C++,Boost,C++11,我已经创建了这个squareList类,当我编译它时,它会给我带来很多错误,我不知道有人能帮我解决这些错误吗 更新:我在~square_list(){}之后注释我的所有代码,并将每个错误精确定位到列表数据 ///#include "LinkedList.hpp" #include <vector> #include <cassert> #include <iostream> #include <iomanip> #include <math.
///#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();
//}
};
//#包括“LinkedList.hpp”
#包括
#包括
#包括
#包括
#包括
#包括
#包括
模板
类方格表
{
typedef T_uu值_u类型;
typedef std::size\u t size\u type;
typedef T_&reference;
类型定义T_uu常数和常数参考;
typedef T_*指针;
typedef T_u常数*常数指针;
typedef T_*迭代器;
typedef T_u常量*常量迭代器;
typedef std::ptrdiff_t difference_type;
typedef std::reverse_迭代器reverse_迭代器;
typedef std::reverse_迭代器const_reverse_迭代器;
//对于标头vectorend()==nullptr)
//返回1;
//否则
//返回0;
//}
//列表::迭代器begin(){
//返回data.begin();
//}
//列表::迭代器end(){
//返回data.end();
//}
};
错误1错误C2143:语法错误:缺少“;”在“之前,第一个问题是这条线
list<T> data<T>;
您甚至可以利用退货类型扣减:
auto begin() -> decltype(data.begin());
auto end() -> decltype(data.end());
您的模板参数是
T
,但您所指的是一个名为T
的未定义参数。试着改变
list<T> data<T>;
列表数据;
到
列表数据;
另外,尝试注释类声明和编译中的所有内容。然后一次取消一行注释,并处理添加每行后出现的任何错误。似乎编译器错误是由私有构造函数引起的,这段代码可以编译,希望对您有所帮助
#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;
}
#包括
#包括
#包括
#包括
#包括
#包括
#包括
使用名称空间std;
#定义空ptr空
模板
类方格表
{
公众:
typedef T_uu值_u类型;
typedef std::size\u t size\u type;
typedef T_&reference;
类型定义T_uu常数和常数参考;
typedef T_*指针;
typedef T_u常数*常数指针;
typedef T_*迭代器;
typedef T_u常量*常量迭代器;
typedef std::ptrdiff_t difference_type;
typedef std::reverse_迭代器reverse_迭代器;
typedef std::reverse_迭代器const_reverse_迭代器;
//对于标头vectorend()==nullptr)
返回1;
其他的
返回0;
}
/*列表::迭代器begin(){
返回data.begin();
}
列表::迭代器结束(){
返回data.end();
}*/
};
int main()
{
方形列表方形列表;
返回0;
}
您还可以使用名称空间std编写
代码>在类定义之前。我看到的唯一问题是列表数据
,它应该是列表数据
。除此之外,我看不出还有其他问题。你确定这段代码会重现所显示的错误吗?是的,它会重现,没有用?既然你键入了定义T_u为value_utype,你应该使用value_utype来代替,你能看到更新吗?因为我在~square_list(){}之后注释了所有的东西不,我有boost测试单元作为我的主要部分,还有许多错误来自列表数据;在我用您的答案行更新之后,我不知道ibtw有什么问题,如果您想编译begin()和end()函数,那么应该在返回值之前使用typename
list<T> data<T>;
list<T_> data;
#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;
}
list<value_type> data;
std::list<value_type> data;