Quantcast
Channel: Active questions tagged header - Stack Overflow
Viewing all articles
Browse latest Browse all 707

How to include functions with auto return type from header file into multiple cpp files

$
0
0

I want to define a function of auto return type in such a way, that I can call it from multiple .cpp files if I include the header. I have 4 files

head.hpp - where the function is

#ifndef HEAD_HPP#define HEAD_HPP auto f();#endif

head.cpp - where the function is declared

#include "head.hpp"auto f(){    return [](){        return 10;    };}

test1.cpp - where it is used

#include "head.hpp"int foo(){    auto func = f();    return f();}

main.cpp - where it is used as well

#include "head.hpp"int foo();int main(){    auto fu = f();    return fu() + 5 + foo();}

All files are compiled togetherI still get the error:

error: use of ‘auto f()’ before deduction of ‘auto’

auto fu = f();


Viewing all articles
Browse latest Browse all 707

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>