预期的类型得到了Element c ++

时间:2018-11-18 02:14:45

标签: c++ object vector

我正在尝试制作一个包含元素周期表元素的对象/类型。但是,当我尝试使用该对象的向量作为参数时,出现此错误消息expected a type, got ‘Element’

到目前为止,这是我的代码:

#include <iostream>
#include <string>
#include <vector>

using namespace std;

Element(int AtomicNumm, string Symboll, string Namee, double Weightt, 
int Neutronss, int Protonss, string ElectronConfigg) {
    string Name = Namee;
    int AtomicNum = AtomicNumm;
    string Symbol = Symboll;
    double Weight = Weightt;
    int Neutrons = Neutronss;
    int Protons = Protonss;
    string ElectronConfig = ElectronConfigg;
}
string returnElement(vector<Element> vec, string input) { // error here
    if (input.size() == 2) {
        for (int i = 0; i < vec.length(); i++) {

        }
    }
    return "";
}

int main(int argc, char*argv[]) {
    vector<Element> PT;
    string userinput (argv[1]);

    return -1;
}

此外,我还是c ++的新手。如果此处的对象完全不同,请告诉我。 (来自Java)

1 个答案:

答案 0 :(得分:2)

那是因为您尚未在程序中声明“ Element”。从句法上讲,它接近于构造函数的定义。

为使您的程序正常工作,我想您可以对现有元素进行以下修改:

class Element {
    // your definition of element Here:

    // also include default constructor without any implementation 
    Element() {}
};