Last active
December 29, 2015 13:29
-
-
Save ffedoroff/7678054 to your computer and use it in GitHub Desktop.
I hate cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <StandardCplusplus.h> | |
| #include <boost_1_51_0.h> | |
| #include <vector> | |
| #include "Arduino.h" | |
| using namespace std; | |
| class BaseSensor { | |
| public: | |
| const char* name; | |
| virtual bool is_sonic() {return false;}; | |
| BaseSensor(const char* name_){ name = name_; } | |
| }; | |
| class SonicSensor: public BaseSensor { | |
| public: | |
| virtual bool is_sonic() {return true;}; | |
| SonicSensor(const char* name_):BaseSensor(name_) { } | |
| }; | |
| vector<BaseSensor*> array; | |
| void setup() { | |
| Serial.begin(115200); | |
| Serial.println("setup"); | |
| array.push_back(new BaseSensor("base")); | |
| array.push_back(new SonicSensor("sonic")); | |
| } | |
| void loop() { | |
| for(int i=0; i < array.size(); i++) { | |
| Serial.print("name="); | |
| Serial.print(array[i]->name); | |
| Serial.print(" is_sonic="); | |
| Serial.print(array[i]->is_sonic()); | |
| Serial.println(" "); | |
| } | |
| delay(1000); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment