Which I can understand… So I am not sure that there can be a better way than what I showed in my previous post
Or perhaps there is ?
Or maybe you just did it wrong? I don't know what to tell you; works for me.
Code:
#include <string>
#include <vector>
#include <iostream>
class ArrayWrapper
{
public:
ArrayWrapper(std::string label, std::initializer_list<double> inits = {})
: lbl_(label), arr_(inits) // constructor
{
}
~ArrayWrapper() = default; // destructor
ArrayWrapper(ArrayWrapper const &) = default; // copy constructor
ArrayWrapper& operator=(ArrayWrapper const &) = default; // copy assignment
ArrayWrapper(ArrayWrapper&&) = default; // move constructor
ArrayWrapper& operator=(ArrayWrapper&&) = default; // move assignment
ArrayWrapper(ArrayWrapper const & other, std::string label)
: ArrayWrapper(other)
{
lbl_ = label;
}
void
dispContent()
{
std::cout << "Array \"" << lbl_ << "\" : ";
for(const auto elem : arr_) {
std::cout << elem << ", ";
}
std::cout << std::endl;
}
private:
std::vector<double> arr_;
std::string lbl_;
};
int main()
{
ArrayWrapper a1("a1", {1, 2, 3});
ArrayWrapper a2(a1, "a2");
a1.dispContent();
a2.dispContent();
}
Maybe you can spot the difference between my listing and yours.
Here is how I compiled:
Code:
-*- mode: compilation; default-directory: "c:/Users/jk/Desktop/" -*-
Compilation started at Thu May 26 11:30:41
g++ -std=c++11 galdor.cpp
Compilation finished at Thu May 26 11:30:42
g++ (GCC) 4.8.1
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.