![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| removing pattern which is spread in multiple lines | sabyasm | Shell Programming and Scripting | 2 | 05-13-2008 02:19 AM |
| Concatenating multiple lines to one line if match pattern | phixsius | Shell Programming and Scripting | 13 | 01-24-2008 08:02 PM |
| Pattern searching pattern in c files | murthybptl | Shell Programming and Scripting | 6 | 11-17-2007 06:15 AM |
| multiple pattern split in perl | umen | Shell Programming and Scripting | 3 | 07-31-2006 11:43 PM |
| Un-Compiling Files ?? | tripp4337 | UNIX for Advanced & Expert Users | 2 | 03-09-2003 11:34 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hi all,
I have been working with java for awhile and because of my school projects I needed to switch C++. I tried to implement some patterns in C++ but unfortunately I couldn't. Specifically, I tried to implement abstract factory pattern but since I used separated files (habitual behavior from java Here is my code: Code:
//run.cpp
#include <iostream>
using namespace std;
int main(){
HFact* fact;
#ifdef LINUX
HFact* fact = new HelloLinFact;
#elif WINDOWS
//HFact* fact = new HelloWinFact;
cout<<"At the moment this implementation is not valid..."<<endl;
#endif
CHello* hello = fact->getHelloNormal();
hello->say();
hello = fact->getHelloReversed();
hello->say();
hello = fact->getHelloWorld();
hello->say();
return 0;
}
//HFact.cpp
class HFact {
public:
extern virtual CHello* sayHelloNormal() = 0;
extern virtual CHello* sayHelloRev() = 0;
extern virtual CHello* sayHelloWorld() = 0;
};
//CHello.cpp
class CHello{
public:
virtual void say() = 0;
};
//HelloLinFact.cpp
class HelloLinFact : public HFact {
public:
CHello* getHelloNormal() {
return new HelloLinNormal;
}
CHello* getHelloReversed(){
return new HelloLinReversed;
}
CHello* getHelloWorld(){
return new HelloLinWorld;
}
};
//HelloLinNormal.cpp
#include <iostream>
class HelloLinNormal : public CHello(){
public:
void say(){
cout>>"HelloNormal class says: Hello!";
}
}
//HelloLinReversed.cpp
#include <iostream>
class HelloLinReversed : public CHello{
public:
void say(){
cout<<"HelloLinReversed says: olleH";
}
}
//HelloLinWorld.cpp
#include <iostream>
class HelloLinWorld : CHello{
public:
void say(){
cout<<"HelloLinWorld says: Hello World!";
}
}
Thanks for your helps in advance Info. about my environment: Linux 2.6.24-18-generic i686 GNU/Linux gcc version 4.2.3 (Ubuntu 4.2.3-2ubuntu7) editor vim |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
let's start with this:
Code:
g++ file1.cpp file2.cpp file3.cpp -o myprogram |
|
#3
|
|||
|
|||
|
I think I should add the .cpp files using #include (and also I need to change the extension names to .hpp except run.cpp).
Thanks... |
|
#4
|
|||
|
|||
|
chnaged color
you have a small error
you wrote : void say(){ cout>>"HelloNormal class says: Hello!"; } but it should be void say(){ cout<<"HelloNormal class says: Hello!"; } Last edited by vovan; 06-11-2008 at 07:00 AM. Reason: changed color |
|
#5
|
|||
|
|||
|
Oups, thanks
|
|||
| Google The UNIX and Linux Forums |