lundi 16 janvier 2023

CPP Cross use methods in different CPP files throws "was not declared in this scope"

I have following files

  • main.cpp
  • common.h
  • A.cpp
  • A.h
  • B.cpp
  • B.h

Some pseudo code:

main.cpp:

#include "common.h"
#include "A.h"
#include "B.h"

void main(....) {
    funca1();
}

A.h:

#pragma once
funca1();
funca2();

B.h:

#pragma once
funcb1();
funcb2();

A.cpp:

#include "A.h"
#include "B.h"

void funca1() {
    funcb2();
}

void funca2() {
    // do stuff
}

B.cpp:

#include "A.h"
#include "B.h"

void funcb1() {
    funca2();
}

void funcb2() {
    // do stuff
}

Compiling this throws errors like

firmware\A.cpp:122:73: error: 'funcb2' was not declared in this scope

This is an arduino project I'm trying to convert from .ino files to generic CPP code to be comilable in platformio - and it's driving me crazy :/

Aucun commentaire:

Enregistrer un commentaire