1
操作系统:Linux Mint的15肉桂 G ++:4.7.3(Ubuntu的/ Linaro的4.7.3-1ubuntu1)非模板继承
我从一个不继承模板类得到以下错误-template类G ++:
In file included from common/bChain.h:13:0,
from common/bProtein.h:12,
from common/bProtein.cpp:12:
common/bPeptide.h:27:31: error: expected template-name before ‘<’ token
common/bPeptide.h:27:31: error: expected ‘{’ before ‘<’ token
common/bPeptide.h:27:31: error: expected unqualified-id before ‘<’ token
几个类似的问题已经在这里问:
http://stackoverflow.com/questions/10265861/error-expected-class-name-before-token-with-templates (template inheriting from template)
http://stackoverflow.com/questions/10548742/c-inheritance-and-templates-not-compiling (uninitialized members in base class)
,但他们每个人的回答不同的问题。 This post建议以下应该与VisualStudio一起工作我认为g ++是一个错误。这篇文章是最接近的,但并没有完全解决这个问题。
我有三个类,VertexSet
,Peptide
和Chain
。 VertexSet
是一个模板类,Peptide
是一个非模板类,从VertexSet
继承,并从肽Chain
继承:
VertexSet.h
:
#ifndef B_VERTEXSET_H
#define B_VERTEXSET_H
//////////////// STL
#include <vector>
//////////////// project
#include <Vertex.h>
#include <Spatial.h>
#include <Pool.h> // for pool resources
namespace griddock { template <typename T> class VertexSet; };
/** @brief \c VertexSet \c
* @author Stephen J. Bush
* @copyright Creative Commons Attribution Non-Commercial License V2.0
* @copyright Creative Commons Attribution ShareAlike License V3.0
* @par
*/
template <typename T>
class griddock::VertexSet
: virtual public Spatial
{
/////////////////////////////////////////////////////////////////////
// Tor
protected:
VertexSet();
VertexSet(const VertexSet &rhs);
public:
~VertexSet();
/* ... more functions here ...*/
};
#define GVXS griddock::VertexSet<T>
////////////////////////////////////////////////////////////////////////
///@name Tor
///@{
template <typename T>
GVXS::VertexSet()
: vertex_(),
min_(),
max_()
{
}
template <typename T>
GVXS::VertexSet(const VertexSet &rhs)
: vertex_(rhs.vertex_),
min_(),
max_()
{
}
template <typename T>
GVXS::~VertexSet()
{
clear();
}
///@}
// .
////////////////////////////////////////////////////////////////////////
#undef GVXS
#endif
Peptide.h
#ifndef B_PEPTIDE_H
#define B_PEPTIDE_H
//////////////// STL
#include <vector>
#include <string>
//////////////// project
#include <Pool.h>
#include <Residue.h>
#include <Spatial.h>
#include <Vertex.h>
#include <VertexSet.h>
#include <File.h>
#include <IPeptide.h>
namespace griddock { class Peptide; };
/** @brief \c Peptide \c implements a data structure to store protein residues
* @author Stephen J. Bush
* @copyright Creative Commons Attribution Non-Commercial License V2.0
* @copyright Creative Commons Attribution ShareAlike License V3.0
* @par
*/
class griddock::Peptide
: virtual public VertexSet<Residue>,
virtual public IPeptide
{
/////////////////////////////////////////////////////////////////////
// Tor
public:
Peptide();
Peptide(const Peptide &peptide);
~Peptide();
/* ...other functions here...*/
};
#endif
Peptide.cpp
//////////////// header
#include <Peptide.h>
//////////////// STL
#include <vector>
#include <string>
//////////////// project
#include <Residue.h>
#include <File.h>
using namespace std;
using namespace griddock;
#define GPEP Peptide
////////////////////////////////////////////////////////////////////////
///@name Tor
///@{
GPEP::Peptide()
: VertexSet<Residue>()
{
}
GPEP::Peptide(const Peptide &peptide)
: VertexSet<Residue>(),
vertex_(peptide.vertex_),
chainid_(peptide.chainid_)
{
}
GPEP::~Peptide()
{
clear();
}
///@}
// .
////////////////////////////////////////////////////////////////////////
原来所有我需要的是确保'Chain'明确称为'Peptide'构造:'链():肽(){}' – muppetjones
试过了。发布我自己的答案之前必须等待8小时= /。有趣的是,StackOverflow是我的[泰迪熊](http://cm.bell-labs.com/cm/cs/tpop/debugging.html) – muppetjones
您应该了解[SSCCE](http:// sscce。 org /):简短的,自包含的,可编译的例子(或者在你的情况下不能编译)。通常情况下,通过将问题简化为最基本的要求,解决方案将自行出现......这个问题会更加有趣;因为它提供了一段文字(很长时间!),但未能提供诊断中提到的“bChain.h”... –