0
我想創建一個程序,其行爲有所不同,具體取決於要編譯的兼容附加源代碼文件(其中有些人可能會添加一些不同的功能)。我想到了函數重載,類似於(非編譯)下面的代碼:取決於源代碼文件集的C++程序行爲
file1.cpp:
#include <iostream>
#include <string.h>
using namespace std;
class base {
public:
void ausgeb() { cout<<"here output base"<<endl; }
};
class derive: public base;
int main(int argc, char** argv)
{
derive beisp;
beisp.ausgeb();
}
file2.cpp:
#include <iostream>
#include <string.h>
using namespace std;
class base;
class derive : public base
{
public:
void ausgeb() { cout<<"here output derive"<<endl; }
};
現在我想的是:
g++ -o o1 file1.cpp file2.cpp
and
g++ -o o2 file1.cpp
應產生具有不同輸出的可執行文件。 可能有滿足這種需求的可能性嗎?
在'file2.cpp'中,可以在文件範圍內有一個對象,其構造函數使用[pimpl](https://en.wikipedia.org/wiki/Opaque_pointer#C)來轉換'derive'的實現。 2B.2B)習語。 –