简体   繁体   English

令牌前的预期不合格ID

[英]Expected unqualified-id before token

Edit: One of the sites I've looked at that leads me to believe my syntax is correct: http://www.cprogramming.com/tutorial/templates.html 编辑:我看过的站点之一使我相信我的语法是正确的: http : //www.cprogramming.com/tutorial/templates.html

I've explored around Google a good deal before coming here to ask this question, since near as I can tell I've written things properly according to the examples that I have seen. 在我来问这个问题之前,我已经在Google周围进行了很多探索,因为据我所知,我已经根据所看到的示例正确地编写了东西。 For a homework assignment, writing a template class that does some extremely basic math stuff (sum, average, minimum, maximum, etc). 对于家庭作业,编写一个模板类,该类做一些非常基础的数学运算(求和,平均值,最小值,最大值等)。 When I attempt to compile to try and start debugging, I end up with the following error. 当我尝试编译以尝试开始调试时,最终出现以下错误。

error: expected unqualified-id before '<' token

Following is somewhat snipped code, prototypes and a few lines before the chunk that errors. 以下是一些被截断的代码,原型以及出错的代码块之前的几行。 The code throws the error on the second line (the ones that start with lessthansymbol myType greaterthansymbol). 该代码在第二行上引发错误(以lessthansymbol myType开头的代码大于somesymbol)。 I'm sure once I get past this I'll have plenty more things to debug with the program, but this is completely holding me up at the moment. 我敢肯定,一旦我克服了这个麻烦,我将有更多的东西要用该程序进行调试,但是此刻完全让我停滞不前。

template <class myType>
class simpleSet
{
    public:

    static const int VALUE_MAX = 1000;
    static const int CNT_MIN = 10;
    static const int CNT_MAX = 500;

    simpleSet();
    simpleSet(int, myType[]);
    ~simpleSet();
    void gnomeSort();
    void generateNewSet(int);
    myType minimum() const;
    myType maximum() const;
    myType median() const;
    myType sum() const;
    myType average() const;
    myType linearRegression(const simpleSet&) const;
    myType getDatum(int) const;
    void setDatum(int, myType);
    int getLength() const;
    void printSet() const;
    int readCount();

private:

    int setLength;
    myType *mySet;
};

template <class myType>
void simpleSet<myType>::generateNewSet(int size)
{
    setLength = size;
    for (int i = 0; i < setLength; i++)
    {
        mySet[i] = static_cast<myType>((myType(rand()%VALUE_MAX)));
        if (mySet[i] < 1 || mySet[i] > VALUE_MAX)
        {
            i--;
            continue;
        }
    }
}

template <class myType>
<myType> simpleSet<myType>::maximum() const
{
    myType worker = mySet[0];
    for (int i = 0; i < setSize; i++)
    {
        if (worker < mySet[i]) worker = mySet[i];
    }
    return worker;
}

template <class myType>
<myType> simpleSet<myType>::minimum() const
{
    myType worker = mySet[0];
    for (int i = 0; i < setSize; i++)
    {
        if (worker > mySet[i]) worker = mySet[i];
    }
    return worker;
}

template <class myType>
<myType> simpleSet<myType>::median() const
{
    if (setSize == 1) return mySet[0];
    else if ((setSize % 2) == 1) return (mySet[(setSize/2)]);
    else return (average((mySet[setSize/2] + mySet[(setSize/2)-1])));
}

template <class myType>
<myType> simpleSet<myType>::sum() const
{
    myType temp;
for (i = 0; i < setSize; i++) temp = temp + mySet[i];
return temp;
}

template <class myType>
<myType> simpleSet<myType>::average() const
{
    return (mySet.sum()/setSize);
}

template <class myType>
<myType> simpleSet<myType>::getDatum(int item) const
{
    return(myset[item]);
}

You don't need <myType> on all the return values. 您不需要所有返回值都<myType> Just myType (no angle brackets) Also don't need to include <myType> in the class scope (ie myType simpleSet::median() . 只是myType (没有尖括号)也不需要在类范围内包括<myType> (即myType simpleSet::median()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM