#Redefinition on the same line (Yes I ve inlcude guards)

47 messages ยท Page 1 of 1 (latest)

chilly nimbus
#

Hi ! You all.
I am reimplementing the STL vector in C++98 as an exercise and so far so good but I stumbled upon a compilation error I can't make sense of.
I have been unable to produce a snippet of what's wrong because it's too big. Instead I have made a replit : https://replit.com/join/bbfribyaff-cassepipe
You can also see what's wrong on your machine with
git clone https://github.com/cassepipe/kontainerz and just running make. What it does is build to executables, one with std::vector and one with my own ft::vector and compare their ouptut.
Before you ask, yes I double checked all my include guards

safe tapirBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For more information use !howto ask.

novel wolf
#

replit requires an account

chilly nimbus
#

@novel wolf I can't upload various files to godbolt right ?

novel wolf
chilly nimbus
#

Since it's a compilation issue it does not make sense to combine everythin in one source file

#

Oooooooh

novel wolf
#

alternatively to tree mode, it actually very much makes sense to combine everything into one file ๐Ÿ˜›

#

#include is a dumb copy-paste

chilly nimbus
#

I tried many times, I have an awk script for that and then I have to remove all my inlcudes but it failed somehow I cna't remember why

#

Do you happen to how to give godbolt a makefile ?

novel wolf
#

tree mode takes a *cmakefile

chilly nimbus
#

Oh it's jsut cmake apparently

novel wolf
#

here

chilly nimbus
#

Ha, damn i have to learn Cmake

novel wolf
#

I don't know cmake, I just copy paste from google yamikek

chilly nimbus
#

Lol, ok

#

but calling cmake or cmake --build . does not work

#

I mean could someone just git clone that on his desktop, run make and see what he understands

#

Damn it's so hot here

#

It's turning into a nightmare

novel wolf
#

If your test code is reduced to

void test_vector()
{
    test_vector_begin();
}

void test_vector_assign()
{
    {
        vector<int> my_vec;
        for (vector<int>::size_type i = 0; i < 42; ++i)
            my_vec.push_back(i + 1);
        std::cout << "my_vec" << std::endl;
        std::cout << "size : " << my_vec.size() << std::endl;
        for (vector<int>::iterator it = my_vec.begin(); it != my_vec.end(); it++)
        {
            std::cout << *it;
            if (it + 1 != my_vec.end())
                std::cout << " ";
        }
    }
}

void test_vector_begin()
{
    {
        const vector< int > my_const_vec(10, 42);
        vector< int >::const_iterator constIt = my_const_vec.begin();
    }
}
#

the code compiles if you comment out the for (vector<int>::iterator it = my_vec.begin(); it != my_vec.end(); it++) part

#

something about things getting confused with the const iterator

chilly nimbus
#

I know but I don't understand the problem

#

And I am not a total noob, I kinda know what I am doing

#

I am saying so that don't think I don't understand the basics of compilation, templating etc.

novel wolf
chilly nimbus
#

Oh thank you so much

novel wolf
#

the problem and solution is: ||Both S instantiations create that friend template definition so instead only make the friend declaration in the class https://godbolt.org/z/ajobo4sh1||

chilly nimbus
#

Haa this is tempting

#

Thank you so much. I'll give myself another ten minutes before I look

novel wolf
#

that is a good idea ๐Ÿ˜„

chilly nimbus
#

Damn I'd have never thought of that, I thought the compiler was smart enough to deal with that

#

The template engine is midway through a dumb C preprocessor and generic type deduction, what a weird beast

novel wolf
#

this is where C++ gets extremely intricate and complicated

#

unfortunately ๐Ÿ˜ฆ

chilly nimbus
#

It did solve my problem but now I have a linker problem

#

The linker complains about not being able to find the operator- definition on the two iterators

#

I am trying to condense it into somthing manageable like you didi

safe tapirBOT
#

@chilly nimbus

This question thread is being automatically closed. If your question is not answered feel free to bump the post or re-ask. Take a look at !howto ask for tips on improving your question.

novel wolf
#

oh shit

#

I fucked up