Skip to content

Instantly share code, notes, and snippets.

@akindyakov
Last active May 30, 2018 10:18
Show Gist options
  • Save akindyakov/7aea290e534674915fa46e3e795bdf29 to your computer and use it in GitHub Desktop.
Save akindyakov/7aea290e534674915fa46e3e795bdf29 to your computer and use it in GitHub Desktop.
% g++ -std=c++11 -c main.cpp [0]
main.cpp: In function ‘int main()’:
main.cpp:8:25: error: invalid use of incomplete type ‘class Status’
std::cout << f.second().str() << '\n';
^
In file included from main.cpp:1:0:
first.h:3:7: error: forward declaration of ‘class Status’
class Status;
#include "first.h"
#include "status.h"
Status First::second() const {
return Status{};
}
#pragma once
class Status;
class First {
public:
explicit First() = default;
Status second() const;
};
#include "first.h"
#include <iostream>
int main() {
auto f = First();
std::cout << f.second().str() << '\n';
}
#include "status.h"
std::string Second::str() const {
return std::string{"hello"};
}
#pragma once
#include <string>
class Status {
public:
explicit Status() = default;
std::string str() const;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment