#Function template has already been defined

53 messages · Page 1 of 1 (latest)

magic jungleBOT
#

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 tips on how to ask a good question run !howto ask.

solid jackal
#

It may just be easier to provide your own code, even if it is nearly identical. People answered their issue so shouldn't it answer yours?

#

If all you did is change the file type/extension, that makes absolutely no difference. All the compiler does is read the code and compile it, it doesn't care what extension you give the file.

wooden pollen
#

Stack.tpp

#

@solid jackal Last month I first encountered this but I gave up and just made the declarations all inside the template header file which worked but I assume isn't great practice so I am trying to get to the bottom of it

solid jackal
wooden pollen
#

@solid jackal doing this works just fine

#

Though if I split them it's where I just get random laundry list of errors

solid jackal
#

I realised it seems like you're doing it wrong, the way a templated class with a template header works is:

example.hpp

template<typename Type>
class Example {
public:
    void DoSomething();
};

#include "example.tpp"
example.tpp

template<typename Type>
void Example<Type>::DoSomething() {
    DidAThing();
}
#

If you're not required to use a template implementation file, it may be a lot easier to start off implementing it all within the header

#

But hopefully that example will help

wooden pollen
#

@solid jackal this is how my book did it?

wooden pollen
solid jackal
wooden pollen
#

Not sure why

#

Though I first tried it without the #include "Stack.h" and with and both worked

solid jackal
#

Are you using visual studio?

wooden pollen
#

Yeah

#

Visual Studio 2022

solid jackal
#

It has a crazy annoying bug where it sometimes doesn't compile all of the files you modified

#

Don't blame yourself for that one

#

I've assigned a shortcut to build all, and as soon as i see weird behaviour, I just build the whole project everytime I run it from then onwards

#

Usually it only happens to moderately sized projects

wooden pollen
#

Doesn't hitting start without debugger build all or no?

solid jackal
#

Thats the bug

#

Sometimes it just won't compile some of the files you modified

wooden pollen
#

I see

solid jackal
#

You can check the console to see which ones were

wooden pollen
#

Does a restart not do anything

solid jackal
#

Not for me, it might have something to do with the cache

#

If you show hidden files and delete the .vs folder, it might work

#

But I've found i prefer to just build all everytime

wooden pollen
#

Do you VS Code or VS?

solid jackal
#

VS

#

It might be best to google if anybody have a solution by now, im just so used to building all now

#

But there might be a patch or whatever

wooden pollen
#

hmm

#

what would I google?

solid jackal
#

Visual studio not compiling all source files?

#

Sometimes its hard to tell when its just not compiling a header and not compiling a source

#

But either way I still find it stupid design

#

Apparently its intended behaviour if you modify a header file then it doesn't compile it

#

🤷‍♂️ I hate it but its the best of the worst to me

#

I also see the sun rising so I better go, I hope that gets you sorted

wooden pollen
#

Thanks for the help @solid jackal

magic jungleBOT
#

@wooden pollen

Please Do Not Delete Posts!

Please don't delete forum posts. They can be helpful to refer to later and other members can learn from them. In the future you can use !solved to close a post and mark a post as solved.

wooden pollen
#

!solved

magic jungleBOT
#

Thank you and let us know if you have any more questions!

This thread is now set to auto-hide after an hour of inactivity

wooden pollen
#

@solid jackal Damn it is happening again on another project.

wooden pollen
#

!solved