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
#Redefinition on the same line (Yes I ve inlcude guards)
47 messages ยท Page 1 of 1 (latest)
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 I can't upload various files to godbolt right ?
Since it's a compilation issue it does not make sense to combine everythin in one source file
Oooooooh
alternatively to tree mode, it actually very much makes sense to combine everything into one file ๐
#include is a dumb copy-paste
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 ?
tree mode takes a *cmakefile
Oh it's jsut cmake apparently
Here the link without all the cruft https://godbolt.org/z/KM7Y8G1WM
Ha, damn i have to learn Cmake
I don't know cmake, I just copy paste from google 
Lol, ok
I have put that in the roor of my project : https://dpaste.com/BZLNVSKMC
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
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
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.
Here's a minimal reproducible example of the problem https://godbolt.org/z/G3E4qro4x
Oh thank you so much
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||
Haa this is tempting
Thank you so much. I'll give myself another ten minutes before I look
that is a good idea ๐
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
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
@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.