Debugging the error: expected constructor, destructor, or type conversion

Hi all, I'm relatively new to C++ and trying to create libraries. This library contains a function that shortens strings into the length given by the user.
The driver program prompts the user for the string and the length they want to shorten it to, it's output should look something like:

thestartofthestri...endofthestring

My problem is that when I compile it, I get this error message about my header file:
"error: expected constructor, destructor, or type conversion before (function name"
about lines 11, 14, and 17; (thefirsthalf, thesecondhalf, and the ellipsify functions).

Header file:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#ifndef ELLIPSIFY_FUNCTIONS_LIBRARY
#define ELLIPSIFY_FUNCTIONS_LIBRARY

//Add a level for my odd/even test without an if statement
int symmetryinator (int strnglngth);


int keepperend (int strnglngth, int maxlength);


std::string thefirsthalf (std::string s, int keep);


std::string thesecondhalf(std::string s, int keep);

//ALL TOGETHER NOW
std::string ellipsify (std::string s, int maxlength);

#endif


Implementation file:
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
#include "ellipsify.h"
#include <iostream>
#include <string>
using namespace std;

//1 UP 
//....a level. The one line even/odd calculation without an "if"
int symmetryinator (int strnglngth) {
	return (strnglngth % 2);
}

//calculates how many chars to keep per end
int keepperend (int strnglngth, int maxlength) {
	int n=((maxlength+symmetryinator(strnglngth)/2)-2);
	return n;
}

//gets the actual string to be displayed...well, the first part anyway

string thefirsthalf (string s, int keep) {
	string first=s.substr(0,keep);
	return first;
}

//and now the second part
string thesecondhalf(string s, int keep) {
	int endindex=s.length()-keep;
	string second=(s.substr(endindex,keep));
	return second;
}

//putting it all together into a function
string ellipsify (string s, int maxlength) {
	string ellipsis="...";
	int keep_per_end=keepperend(s.length(), maxlength);
	string front=thefirsthalf(s, keep_per_end);
	string back=thesecondhalf(s, keep_per_end);
	string abbreviated= front + ellipsis + back;
	return abbreviated;
}


Driver:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include "ellipsify.h"
#include <iostream>
#include <string>
using namespace std;

int main() {
	int max;
	string thestring;
	cout<<"max length";
	cin>>max;
	cout<<"enter string";
	getline(cin, thestring);
	
	string shortenedline= ellipsify(thestring, max);
	cout<<shortenedline;
return 0;
}


Thanks for any help!
Last edited on
Your header file is trying to use std::string, so you need to #include <string>
Oh wow, that cleared everything up. Thank you!
Topic archived. No new replies allowed.