These errors are frustrating me

I am. Getting this error:
Implicit error conversion changes (aka 'unsigned int') to int'

Errors occur at line 50 and 60

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
#include<cstdlib>
#include<iostream>
#include<cstddef>
#include<cstring>
#include<string>
using namespace std;

class StringVar
{
public:
    StringVar(int size);
    StringVar();
    StringVar(const char a[]);    StringVar(const StringVar& string_object);
    ~StringVar();
    int length() const;
    void input_line(istream& ins);
    friend ostream& operator <<(ostream& outs, const StringVar& the_string);
private :
    char *value; //pointer to dynamic array that holds the string value
    int max_length;
};
void conversation(int max_name_size);

int main()
{
    conversation(30);
    cout << "End of demonstration.\n";
    return 0;
}
void conversation(int max_name_size)
{
    StringVar your_name(max_name_size), our_name("Borg");
    cout << "What is your name?\n";
    your_name.input_line(cin);
    cout << "We are " << our_name << endl;
    cout << "We will meet again " << your_name << endl;
   
}
//Uses cstddef and cstdlib
StringVar::StringVar(int size) : max_length(size)
{
    value = new char[max_length + 1];
    value[0] = '\0';
}
StringVar::StringVar() : max_length(100)
{
    value = new char[max_length + 1];
    value[0] = '\0';
}
StringVar::StringVar(const char a[]) : max_length(strlen(a))
{
    value = new char[max_length + 1];
    strcpy(value, a);
}
StringVar::StringVar(const StringVar& string_object) : max_length(string_object.length())
{
    value = new char[max_length + 1];
    strcpy(value, string_object.value);
}
StringVar::~StringVar()
{
    delete [] value;
}
int StringVar::length() const
{
    return strlen(value);
}
void StringVar::input_line(istream& ins)
{
    ins.getline(value, max_length + 1);
}
ostream& operator<<(ostream& outs, const StringVar& the_string)
{
    outs << the_string.value;
    return outs;
}
Sorry I meant to say line 50 and 66
And what did you learn from your previous thread with the same error messages?
http://www.cplusplus.com/forum/beginner/266618/

I am using my cell phone at the moment since my laptop has been stolen. It uses Andriod. The IDE is called CppDroid
Hi, Bopaki. Very sorry for your laptop. I shiver to think what would it mean fro me to loose mine, with years of data inside…

Line 50:
… : max_length( strlen(a) )
It means: initialize the private variable max_length with the value returned by the function std::strlen().

max_length is declared of type int (which is a signed type).
std::strlen() returns a std::size_t (which is a unsigned type).

Please compare:
https://en.cppreference.com/w/cpp/string/byte/strlen


- - -
Line 64-67:
1
2
3
4
int StringVar::length() const
{
    return strlen(value);
}

It means: function (method) StringVar::length() should return an int (which is a signed type).
Instead it returns a std::size_t (which is a unsigned type).
Topic archived. No new replies allowed.