Function not declared in scope

I have made a class and I have an operator overloaded...I have a few members functions (they are members because they use the member data)....I have declared a function which doesn't use any member data and that function is used by the operator += which is overloaded in the class....what happens is when I compile the program the compiles says to me that that function was not declared in the scope...I could do that function a member, but I wouldn't like to do that..how could i do it?? here I post what matter of the program.....

To summarize...I would like to make visible that function without making a member of the class becasue in fact expand function( is the one) doesn't get any member data...

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
 class String{
private:
	static const int short_max = 15;
	int sz;
	char* ptr;
	union{
		int space;
		char ch[short_max +1];
	};
	void check(int n) const{
		if(n<0 or sz<=n){
			throw std::out_of_range("String::at()");
		}
	}
	
	void copy_from(const String& x);
	void move_from(String& x);

public:


	String():sz{0},ptr{ch}{
		ch[0] = 0;
	}
	
String(const char* p):sz{strlen(p)},ptr{(sz<=short_max)?ch : new char[sz +1]},space{0}{
	strcpy(ptr,p);
}

tring& operator+=(char c){
	if(sz==short_max){
		int n = sz+sz+2;
		ptr = expand(ptr,n);   //expand was not declared in this scope
		space = n-sz-2;
	}
	else if(short_max<sz){
		if(space==0){
			int n = sz + sz + 2;
			char* p = expand(ptr,n);  //expand was not declared in 
			delete[] ptr,             //in this scope
			space = n-sz-2;
		}
	else
		--space;
	}
ptr[sz] = c;
ptr[++sz] = 0;

return *this;
}
	
};

	char* expand(const char* ptr,int n){ 		//allocate memory for a string bigger than short_max
	char* p = new char[n];
	strcpy(p,ptr);
	return p;
}

Line 13: #include <stdexcept> missing

Line 30: You're missing the S in String.

Line 54: You either need to declare expand as a member of String, or provide a forward declaration for it. At the point the compiuler processes line 39, it does not know what expand looks like.




but that forward declaration wouldn't have to be in the class scope, would it?
yes, It doesn't thanks
Topic archived. No new replies allowed.