Classes/Vimrc help

Hey all,

I'm coding to touch up on some skills with classes. I'm using Sublivim as a vimrc file and for some strange reason, I'm getting an error with my strcpy() function. I'm getting an error stating that states "no matching function call to 'strcpy'." However, this is odd because I have <cstring> included in my code.

A separate issue is that my code says, "cannot initialize a parameter of type 'char' with an lvalue of type 'char'. I'm not sure why this is the case, but I've been playing with it for too long now.

Another clue to helping me solve this may be that I had to change my vimrc to compile using g++ and not gcc. I'm running a 2014 Macbook Pro Retina (most recent OS). It shouldn't be an issue, but I'm tried switching between several and I'm not seeing this error disappear. I've included my code and some photos of what my vimrc looks like. The arrows indicate that there is an error on the line and those are my problem areas.

Please help me understand what I'm doing wrong!

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
79
80
81
82
83
84
85
  
//.h file
#include <iostream>
#include <cctype>
#include <cstring>

using namespace std;

class Student {

	public:
		Student(int x, int y);
		Student();
		~Student();
		int setFirst (char, int);
		int setLast (char, int);
		int setHeight (int);
		int setWeight (int);
		int displayStudent ();
	private:
		int weight;
		int height;
		char * first;
		char * last;
};

Student::Student()
{
	weight = 0;
	height = 0;
	first = NULL;
	last = NULL;
}
/*
Student::Student(int x, int y)
{
	weight = x;
	height = y;
	first = NULL;
	last = NULL;
}
*/
Student::~Student()
{

	weight = 0;
	height = 0;
	delete [] first;
	delete [] last;
	//again
}
int Student::setFirst (const char firstName, int size)
{
	first = new char[size + 1];
	strcpy(first, firstName);
	return (1);
}

int Student::setLast (const char lastName, int size)
{
	last = new char[size+1];
	strcpy(last, lastName);
	return (1);
}

int Student::setHeight (int h)
{
	height = h;
	return (1);
}

int Student::setWeight (int w)
{
	weight = w;
	return (1);
}

int Student::displayStudent ()
{
	cout << "Name " << first << ' ' << last << endl;
	cout << "Weight" << weight << endl;
	cout << "Height: "<< height << endl;
}



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
//CPP file
#include "class.h"

using namespace std;

int SIZE = 42;

int main()
{
	char tempFirst[SIZE];
	char tempLast[SIZE];
	Student newStudent;
	//Student *s_pointer;

	//strcpy(tempFirst, tempLast);
	int x, y, firstLen, lastLen, success;

	cout << "Enter your first name" << endl;
	cin.get(tempFirst, SIZE, '\n');
	cin.ignore(100, '\n');
	success = newStudent.setFirst(tempFirst, lastLen);


	cout << "Enter your last name" << endl;
	cin.get(tempLast, SIZE, '\n');
	cin.ignore(100, '\n');
	newStudent.setLast(tempLast, lastLen);

	cout << "Enter your weight" << endl;
	cin >> x;
	cin.ignore();
	newStudent.setWeight(x);


	cout << "Enter your height" << endl;
	cin >> y;
	cin.ignore();
	newStudent.setHeight(y);

	cout << "First Name: " << tempFirst << endl;
	cout << "Last Name: " << tempLast << endl;

	cout << "First Length; " << (firstLen = strlen(tempFirst)) << endl;
	cout << "Last Length: " << (lastLen = strlen(tempLast)) << endl;
//overloading operator
	
	

	newStudent.displayStudent();

	return (0);
}

vim is unrelated.


> "no matching function call to 'strcpy'."
> "cannot initialize a parameter of type 'char' with an lvalue of type 'char'
If you don't know what the error means, then don't paraprhase it.
If you know what the error means, then don't paraprhase it.
Write the full error message, including line numbers.

There's a difference between char and char*
Topic archived. No new replies allowed.