Simple Code Need Help - No constructor instance matches argument list

I am following a book on programming in C ++ and I am stuck on vectors. An example from the book:

vector<int> v = {1,2,3};

      

but I am getting the error:

    1   IntelliSense: no instance of constructor "Vector<T>::Vector [with T=int]" matches the argument list
        argument types are: (int, int, int) ../path

      

Also, when I create a string vector:

vector<string> v = {"one", "two", "three"}

      

I am getting this error:

    1   IntelliSense: no instance of constructor "Vector<T>::Vector [with T=std::string]" matches the argument list
        argument types are: (const char [4], const char [4], const char [6]) ../path

      

I am using VS 2013 with 2013 CTP compiler. What am I doing wrong?

+2


source to share


2 answers


To summarize and share what was written in the comments and Bjarne Stroustrup's "std_lib_facilities.h"

header:

  • The header contains a thirteenth vector class named Vector

    for teaching purposes;
  • To make a Vector

    "seamless" replacement for Vector

    the standard library (again, for training purposes), the header contains the following lines:

    // disgusting macro hack to get a range checked vector:
    #define vector Vector
    
          

  • The OP most likely used the title for the first edition of the book (this is a google search result for std_lib_facilities.h

    ), which Vector

    does not have a constructor initializer_list

    (this edition uses C ++ 98, which has no initialization lists).
  • As a result, the compiler complains that it Vector

    does not have a corresponding constructor when it sees vector<int> v = {1,2,3};

    which it becomes vector<int> v = {1,2,3};

    after replacing the macro.


To fix the problem, download and use the correct version of the header.

+4


source


Try to #include <string>

define a string. ANDusing namespace std;



The last line lets you skip std::

infront.

0


source







All Articles