Error 2660 ... function does not take 1 arguments multiple times. Doesn't appear to be the usual goof.

I've been searching for the cause for most of two days now. I'm not a beginning programer, but I am new to C++. suspect I am missing two things or just the concept.
**Error messages **
1> mainperson.cpp
1>c:\prog\upload\mainperson.cpp(19): error C2660: 'personType::getlastname' : function does not take 1 arguments
1>c:\prog\upload\mainperson.cpp(20): error C2660: 'personType::getfirstname' : function does not take 1 arguments
1>c:\prog\upload\mainperson.cpp(21): error C2352: 'personType::print' : illegal call of non-static member function
1> c:\prog\upload\persontype.h(10) : see declaration of 'personType::print'
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// ff     11/11/2010   personType.h
#include <iostream>
#include <string>
#include <cstdio>
using namespace std;

class personType
{
	public:
        void print()  const;  // outputs first and last name
        void setname(string first, string last); //function to set fname an lname to paramters  after firstname = first  and lastname = last
        std::string getfirstname() const; // function to return the first name    after the value of firrst name is returned
        std::string getlastname() const;   // function to return the last name    after the value of last name is returned
        personType(); // default constructor sets first and last name to null strings
        personType(string first, string last); // constructor with parameters
          // destructor
         ~personType();

   private:
       string firstname;    //variable to store firstname
       string lastname;     // varaible to store lastname
  }
;

       void personType::print() const
       {
			cout << firstname << " " << lastname;
       }
       void personType::setname(string first, string last)
       {
           firstname = first;
           lastname = last;
       }
         std::string personType::getfirstname() const
       {
                return firstname;
        }
        std::string personType::getlastname() const
        {
            return lastname;
        }
    personType::personType()    //default constructor
    {
    firstname = "";
    lastname = "";
    }
    personType::personType(string first, string last) //constructor with parameters.
    {
    firstname = first;
    lastname = last;
    }
    ;

******************************* main follows
#include <iostream>
#include <cstdio>
#include <string>
#include "personType.h"

using namespace std;

int main()
{
string fname = "";
string lname = "";

   cout << "enter a first name ";
    cin >> fname;
    cout << "enter a last name ";
    cin >> lname;
    personType::personType(fname, lname);
    personType names(fname, lname) ;
    personType::getlastname(lname);
    personType::getfirstname(fname);
    personType::print();
//    personType::print();
        return (0);
}
Last edited on
Yes, it's the concept. You need to write it like so:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
int main()
{
string fname = "";
string lname = "";

   cout << "enter a first name ";
    cin >> fname;
    cout << "enter a last name ";
    cin >> lname;
    personType names(fname, lname) ;
    names.getlastname(lname);
    names.getfirstname(fname);
    names.print();
        return (0);
}
With '::' the functions are static (you have to write that key word in front of the function within the class) and only connected to the class. With '.' the functions are connected to the object (here: names)
1
2
personType names(fname, lname) ;
names.getlastname(lname);
This is still wrong. The second line should be
 
lname=names.getlastname();
Thanks alot Coder777 and helios I was able to get this after falling over the instantiation block.

Last edited on
Topic archived. No new replies allowed.