C++ How do I to put this constructor in a cpp file? -
i have constructor in .h
file
c(std::string s = "",int = 0,double d = 1) { datamember1 = s; datamember2 = i; datamember3 = d; }
if provide values of string, int , double use values, without them, use default ones. question how refactor put in .cpp
file.
when not refactoring works fine example if declare
c object1("object1", 0, 1), object2;
work, if refactor, object2
cause compile error saying don't have c()
constructor
fwiw:
#include <iostream> #include <string> using namespace std; class c{ public: c(string a= "" , int foo=1, char bar=0); }; c::c(string a, int foo, char bar){ // can go .cpp file cout<<a<<foo<<bar; } int main() { c c("hi",1,'t'); return 0; }
but others stated should google "c++ tutorial"(actually deals similar in classes chapter) or read book. it'll lot frustrating,faster , fulfilling...
Comments
Post a Comment