where is my wrong !

i want to set the name of shape and print it out, but it only show me

It's name is :

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

class shape {
protected:
	string name;
public:

	shape (string y =" ") 
		:name(y){}

	void getname(string namy) {

		name = namy;
	}

	string getn() {
		return name;
	}

};

class circle : public shape {
private:
	int R;
public:
	circle(int l=0) {
		R = l;
}

	void set_the_R (int a) {

		R = a;
	}

	int getr() {
		return R;
		
	}

};

int main() {

	circle T;
	string p = "afsfasf";

        T.getname (p);
	T.set_the_R(2);
	cout << " It's name is "; T.getn();
	
	cout << " \n It's Radius is : "; T.getr();



	
	system("pause");

	return 0;
}

Last edited on
T.getn(); is returning an a string, but you aren't printing it.

change to:
1
2
3
	cout << " Its name is " <<  T.getn();
	
	cout << " \n Its Radius is : " << T.getr();
Thanks Gando but if i say

1
2
3
4
5


	void getn() {
		cout name;
	} 


then i can say onle

1
2
3

T.getn();


is that right ?
If you mean cout << name;, yes, you *can* do that. But that then becomes a really misleading function name -- "getX" usually implies a return value of X.

Likewise,
1
2
3
4
	void getname(string namy) {

		name = namy;
	}

Is a misleading function as well. You are not getting anything. You are setting the name.
Topic archived. No new replies allowed.