I need a your idea

hey guys, I want to know your idea whether returning as code below is correct or not.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
  
class example
{
pubic:
string func_destination();

private:
string destination;
};

int main()
{
string x;
x = func_destination();
cout<<x;
}

string example::func_destination()
{
return destination;
}


You should check whether your standard compliant C++ compiler accepts the syntax. It will complain about line 4, and perhaps about string too.

The possible logical errors ... impossible to say without knowing the intent of the program.
line 14 is wrong. func_destination() is a member function of class example hence you need an instance of example in order to access the function like so:
1
2
3
4
5
6
7
int main()
{
example e;
string x;
x = e.func_destination();
cout<<x;
}
@ OP: No it is not. That is not how you call a classes member function. You are also trying to output an uninitialized variable and not returning anything from Main even though you declared that you would. As keskiverto pointed out, you misspelled "public:" and string and cout should be preceded by their namespace prefix.
Topic archived. No new replies allowed.