Search
 
SCRIPT & CODE EXAMPLE
 

CPP

explicit c++

#include <iostream>
#include <cstring>

Class MyClass{
public:
  explicit MyClass(const char* str){
    std::cout << str << std::endl;
  }
};

int main(int argc, char* argv[]){
  std::string title = "Hello World!";
  MyClass obj1(title); // This will not compile, because with explicit
  //                      keyword we blocked implicit convertion from
  //                      std::string to const char*
  MyClass obj2(title.c_str()) // Now it works, because we paste in a
  //                      const char* with c_str() method!
  
  return 0;
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: how to make a square root function in c++ without stl 
Cpp :: count sort algorithm 
Cpp :: class operator overloading c++ 
Cpp :: how to create a c++ templeate 
Cpp :: polymorphism in c++ 
Cpp :: prime or not in cpp 
Cpp :: Finding square root without using sqrt function? 
Cpp :: prime number c++ 
Cpp :: c++ inheritance constructor 
Cpp :: how to declare a vector of int in c++ 
Cpp :: C++ Pi 4 Decimal 
Cpp :: how to copy vector to another vector in c++ 
Cpp :: loop c++ 
Cpp :: Syntax for C++ Operator Overloading 
Cpp :: array copx c++ 
Cpp :: if argv == string 
Cpp :: converting char to integer c++ 
Cpp :: c++ define constant in class header 
Cpp :: Array declaration by specifying the size in C++ 
Cpp :: for auto c++ 
Cpp :: 2d array of zeros c++ 
Cpp :: cpp vector popback 
Cpp :: round c++ 
Cpp :: cin c++ 
Cpp :: c++ check first character of string 
Cpp :: even and odd numbers 1 to 100 
Cpp :: queue cpp 
Cpp :: book allocation problem in c++ 
Cpp :: pointer to value of others file cpp 
Cpp :: COs trigonometric function 
ADD CONTENT
Topic
Content
Source link
Name
3+7 =