6

I need to convert a class written in C++ 0x to one which compiles in Visual studio 2008. The code uses std::initializer_list.

Following is the code

template <typename data_type>
class symmatrix
{
public:


    typedef data_type         value_type;
    symmatrix(std::initializer_list<T> const& size, value_type ini = value_type())
      : m_data(0), m_memory(false) { resize(size); *this = ini; }
}

has to be converted to old standard understood by VS 2008.

I am really struggling to change 100 lines of new C++ code to old C++. So, please help me.

2
  • 2
    Do you understand that changing the constructor means in all likelihood changing all sites that use that constructor? It's possible to write a constructor that is equivalent semantically but it will not be source-compatible with the old one. Commented Jul 25, 2011 at 7:26
  • 1
    If you are currently (judging from your questions) on producing a VS2008 compatible version of a C++0x (VS2010?) project, I recommend that you take your time to read the documents that lead to the modifications of the standard and what the equivalences in code represent. Depending on how much current code uses that class, and whether you want to maintain the two versions (C++03/0x) you might decide that some features of the class are not worth it and drop them from the C++03 version. Commented Jul 25, 2011 at 7:45

1 Answer 1

5

Instead of an initializer_list you can choose to pass a pair of iterators. But you'll have to change client code as well.

If it is a well-written class, it's bound to have other constructors, such as the one I mentioned. In this case I'd recommend to just remove the overload that takes an initializer_list. Client code may have to be changed as well, if it uses that constructor.

Sign up to request clarification or add additional context in comments.

1 Comment

Sorry I could not get it. Could you suggest with some example.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.