how to declare a reference to a pointer

i would like to create a function which takes in a reference to a pointer.for some reason when i build this, I keep getting cout and endl undeclared identifier.

i am also getting some warning initializing truncation from char to int.



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
  
# include <iostream>


void display(char* & pointer)
{

	cout << *pointer << endl;
	++pointer; 

}



using namespace std;

int main()
{
	char loaded2[] = { 'aa', 'BB' }; 

	//char * p = test;

	char * pp = loaded2;


	display(pp);

	display(pp);


	cout << *pp << endl;

	++pp;

	cout << *pp << endl;



	for (char * p = loaded2; p != loaded2 + sizeof(loaded2) / sizeof(loaded2[0]); ++p)
	{
		
		cout << *p << endl;
	}
  

	system("pause");


}
The error you encountered is due to using namespace std; coming after the 'display' function, so the contents of the std namespace are not available there. Moving line 15 to above line 5 fixes this specific error.

There are warnings about line 19, though.
1
2
3
4
5
6
7
8
9
10
11
test.cpp:19:21: warning: multi-character character constant [-Wmultichar]
  char loaded2[] = { 'aa', 'BB' }; 
                     ^
test.cpp:19:27: warning: multi-character character constant [-Wmultichar]
  char loaded2[] = { 'aa', 'BB' }; 
                           ^
test.cpp: In function ‘int main()’:
test.cpp:19:32: warning: overflow in implicit constant conversion [-Woverflow]
  char loaded2[] = { 'aa', 'BB' }; 
                                ^
test.cpp:19:32: warning: overflow in implicit constant conversion [-Woverflow]


The first two are reported because a character constant (inside 's) is meant to be a single character. The last two, if I understood it correctly, say that both values (that the compiler is probably treating as a 2-byte integer) get truncated to fit the char type, which is 1-byte long on most platforms.

Hope it helps
Last edited on
Topic archived. No new replies allowed.