Category : constructor

I’m a programming student but my professor refuses to explain anything, in this assignment she introduced classes and I’m struggling to understand the constructor concept/syntax. I have a "matching constructor" error on two lines of my code (I’ve marked them with comments, the problem lines of code are both in main.) The code is a ..

Read more

I have a class DLXMatrix with constructor delegation. it as a simple constructor: DLXMatrix::DLXMatrix(int nb_col); And another more advanced one which is currently: DLXMatrix::DLXMatrix(int nb_col, const std::vector<std::vector<int>> &rows) : DLXMatrix(nb_col) { for (const auto &r : rows) // TODO : cleanup if an exception is raised add_row_sparse(r); } However, depending on the input, the call ..

Read more

#include <iostream> #include <string.h> using namespace std; class sorting { private: char str[10]; public: sorting() { int i; for(i=0;i<10;i++) { cin>>str[i]; } } void sort() { int i,j; char temp; for(i=0;i<10;i++) { for(j=i+1;j<10;j++) { if(strcmp(str[j],str[j+1])>0) { strcpy(temp,str[j]); strcpy(str[j],str[j+1]); strcpy(str[j+1],temp); } } } for(i=0;i<10;i++) { cout<<str[i]; cout<<"n"; } } }; int main() { sorting s1; cout<<s1.sort(); ..

Read more

I have a templated class which instantiates an internal object of the template type and its constructor forwards the arguments to the internal object. template<typename T> struct B { template<typename… Args> B(Args&&… args) : m(std::forward<Args>(args)…) {} B(const B& b) = default; B(B&& b) noexcept = default; void operator()() { m(); } T m; }; Also ..

Read more