Ist es möglich, die Funktion foo() von Foo.cpp aufzurufen, ohne den Funktionsnamen Foo :: foo() zu Foo :: newfoo() zu ändern.Aufruf des gleichen Namens Funktion
main.cpp
#include <iostream>
#include "Foo.hpp"
class Foo {
public:
void foo() {
std::cout << "Foo::foo\n";
}
void bar() {
std::cout << "Foo::bar\n";
foo();// need to call foo() function from foo.cpp not Foo::foo()
}
};
int main() {
Foo f;
f.bar();
return 0;
}
Foo.hpp
#ifndef FOO_HPP_INCLUDED
#define FOO_HPP_INCLUDED
void foo();
#endif // FOO_HPP_INCLUDED
foo.cpp
#include "Foo.hpp"
#include <iostream>
void foo(){
std::cout << "foo\n";
}
ps.sorry für mein schlechtes Englisch.
Ist das wirklich ein Problem? Wie geschrieben, sieht Foo.cpp nur eine Definition des Namens 'foo'. Der einzige Konflikt liegt innerhalb der Definition von 'void Foo :: foo()' in 'main.cpp'. Das scheinen die Antworten zu sein. – Potatoswatter