Find the answer to your Linux question:
Results 1 to 2 of 2
Hi, I have the following c++ code and I try to compile it with "g++ -c myCode.cpp" in three different versions of the gcc compiler : ------------------------------------------------------------ #include<vector> using namespace ...
  1. #1
    Just Joined!
    Join Date
    Dec 2009
    Posts
    2

    Post Compilation Problem due to version change - need advice

    Hi,

    I have the following c++ code and I try to compile it with "g++ -c myCode.cpp" in three different versions of the gcc compiler:
    ------------------------------------------------------------
    #include<vector>
    using namespace std;

    int main(){
    vector<vector<int> > myVec;
    //vector<int> myVec;

    myVec.assign(5,0);
    return 0;
    }

    ------------------------------------------------------------
    System 1: Fedora Core release 3, gcc version 4.0.1
    -- Successful compilation
    System 2: CentOS release 5.2, gcc version 4.1.2 20071124 (Red Hat 4.1.2-42)
    -- Successful compilation
    System 3: Fedora release 10, gcc version 4.3.2 20081105 (Red Hat 4.3.2-7) (GCC)
    -- Compilation error as below:
    /usr/lib/gcc/x86_64-redhat-linux/4.3.2/../../../../include/c++/4.3.2/bits/stl_vector.h:992: error: no matching function for call to \u2018std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >::_M_fill_assign(int&, int&)\u2019
    /usr/lib/gcc/x86_64-redhat-linux/4.3.2/../../../../include/c++/4.3.2/bits/vector.tcc:183: note: candidates are: void std::vector<_Tp, _Alloc>::_M_fill_assign(size_t, const _Tp&) [with _Tp = std::vector<int, std::allocator<int> >, _Alloc = std::allocator<std::vector<int, std::allocator<int> > >]


    But while I change vector<vector<int> > to vector<int>, all three compilers are comfortable.
    I want to know the reason for that. Please advise how to get rid of the compilation error. Thanks in advance.

  2. #2
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
    Posts
    8,974
    I don't know for sure because I haven't seen this problem (yet), but what if you tried this:
    Code:
    #include<vector>
    using namespace std;
    
    int main(){
        vector<int> testvec; // Force instantiation of vector<int>
        vector<vector<int> > myVec;
        //vector<int> myVec;
    
        myVec.assign(5,0);
        return 0;
    }
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...