#wierd cpp syntax leading to error

38 messages · Page 1 of 1 (latest)

thin ferry
#

while working on the project there was this error on the main saying Inline function 'MEU::apply_texture' is not defined
main.cpp

#include "helper.hpp"
...

int main() {
  ...

  MEU::apply_texture(viewport, 8*4, image_size); // error
...

helper.hpp

namespace MEU {
...

constexpr void apply_texture(sf::VertexArray& arr,
                             const uint32_t vertex_ammount,
                             const sf::Vector2f texture_size);
...

fading coralBOT
#

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 use !howto ask.

thin ferry
#

its the error from the linter

light marlin
#

try to compile

#

see what the compiler gives you

#

linter can mess up at times

opaque sequoia
#

A constexpr function is implicitly inline, so you need to define it in the header.

#

It looks like you have only a declaration there.

light marlin
#

oh... you're right

#

Didn't see the ;

#

thought the definition was ommited

thin ferry
#

wait so i have to define it on the header?

light marlin
#

Yeah

thin ferry
#

thats wierd.....

light marlin
#

As stabile said, it's inline inherently

opaque sequoia
#

how should constexpr work if there is no definition of the function visible to the compiler?

light marlin
#

So yeah, you can't split the declaration/definition

thin ferry
#

thanks

#

!solves

#

!solved

fading coralBOT
#

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

opaque sequoia
#

btw. do you expect constexpr to actually do anything here? what texture are you going to apply at compile-time?

thin ferry
#

idk....

#

im super new on cpp

#

and compiled languages

opaque sequoia
#

why did you write constexpr then?

thin ferry
#

idk.... maybe because i see other people do that

opaque sequoia
#

then I'd suggest just not adding things that you don't know what they do and get rid of constexpr, instead of moving the definition to the header

thin ferry
#

Well most of the usage of that function, all of it's parameters was known on compile time....

opaque sequoia
#

If it actually makes sense for the function to be evaluated during compilation, then sure, add constexpr and move the definition to the header. But from what I can see that doesn't look likely.

#

Do sf::VertexArray and sf::Vector2f even have constexpr support?

light marlin
thin ferry
#

What does that mean....

#

How do I know if a function is runtime or compile time

light marlin
#

When you define something as constexpr it means that everything that it does can be done at compiletime

#

Take something like sqrt

light marlin