-3

I need help with this error?

molecule.cpp:31:7: error: qualified reference to 'mole' is a constructor name rather than a type wherever a constructor can be declared mole::mole(Atom1(), Atom2() ){

class mole {

private:
        string name;
        int proton;
        int neutron;
        int electron;
        int valence;
public:
        int mass();
        mole();
        mole(Atom, Atom);
        mole(string);
        mole(string,int,int,int);
};


mole::mole()
  {
        name="hydrogen";
        proton=1;
        neutron=0;
        electron=1;
        valence=1;
}

mole::mole(Atom1(), Atom2() ){
        proton= Atom1.p + Atom2.p;
        neutron=Atom1.n + Atom2.n;
        electron=Atom1.e + Atom2.e;
}

In another file:

#include<iostream>

using namespace std;

class Atom {

private:
        string name;
        int proton;
        int neutron;
        int electron;
        int valence;
public:
        int mass();
        Atom();
        Atom(int,int,int);
        Atom(string);
        Atom(string,int,int,int);
};


Atom::Atom(){
        name="hydrogen";
        proton=1;
        neutron=0;
        electron=1;
        valence=1;
}

Atom::Atom(int p, int n, int e){
        proton=p;
        neutron=n;
        electron=e;
}

Atom::Atom(string n){
        name=n;
}

Atom::Atom(string nm, int p, int n, int e){
        name = nm;
        proton=p;
        neutron=n;
        electron=e;
}



int Atom::mass(){
        int mass = proton+neutron;
        return mass;

}
user4581301
  • 33,082
  • 7
  • 33
  • 54
  • Which line is line 31? – Thomas Matthews Apr 26 '17 at 23:55
  • 1
    Change: `mole::mole(Atom1(), Atom2() )` --> `mole::mole(Atom Atom1, Atom Atom2 )` – Richard Critten Apr 26 '17 at 23:56
  • change `mole::mole(Atom1(), Atom2() ){` to `mole::mole(Atom Atom1, Atom Atom2 ){` – eyllanesc Apr 26 '17 at 23:56
  • 1
    Epic would be if the error was on line 6.022140857 × 10^23 – user4581301 Apr 26 '17 at 23:56
  • It appears that you need [good C++ book](http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list). in `mole::mole(Atom1(), Atom2() )` both `Atom1`, and `Atom2` are missing type specifiers, and the brackets (`()`) are not needed. – Algirdas Preidžius Apr 26 '17 at 23:56
  • Off topic: It's generally best to not `using namespace std;` at all, but in a header it can be particularly vicious. Other folk who include the header may suddenly find themselves calling the wrong `swap` or `reverse` or other nonsense that will waste debugging time. – user4581301 Apr 27 '17 at 00:09

2 Answers2

0

So many errors. Let's tidy it up a bit and make it real C++.

mole::mole( const Atom & a, const Atom & b )
    : proton( a.p + b.p )
    , neutron( a.n + b.n )
    , electron( a.e + b.e )
    , valence{}  // or whatever calculation you intended  
{
}
paddy
  • 60,864
  • 6
  • 61
  • 103
0

I'm assuming that Atom is a class that is declared elsewhere? If you wanted to be able to accept two parameters of type Atom in the non-default constructor, you should declare it like so:

mole(Atom atom1, Atom atom2);
...
mole::mole(Atom atom1, Atom atom2) {
    proton = atom1.p + atom2.p
    ....
}
Howard
  • 218
  • 1
  • 9