why Binay scope resolution operator is not used here 14th tutorial

0 Alam Khattak · December 29, 2014
For Constructors Binary scope Resolution operator ": :" is used but in this tutorial its not used.Why?

Post a Reply

Replies

Oldest  Newest  Rating
0 Franz Schmidt · December 29, 2014
You mean something like this?
Here you don't need the :: operator because the function gets defined inside the class:
class MyClass{
public:
MyClass(string s){
name = s;
}
private:
string name;
};
int main(){
MyClass test("Franz");
return 0;
}

If you do it like this you need it:
class MyClass{
public:
MyClass(string);
private:
string name;
};
MyClass::MyClass(string s){
name = s;
}
int main(){
MyClass test("Franz");
return 0;
}

Here the :: is necessary so the programm knows the "MyClass" function aka constructor is part of the class "MyClass"

Hope I understood your question right :D
0 Alam Khattak · December 29, 2014
thanks Franz
  • 1

C++

107,231 followers
About

Used in many types of software including music players, video games, and many large scale applications.

Links
Moderators
Bucky Roberts Administrator