Created
July 8, 2016 19:51
-
-
Save zafarali/a0b4a42d453198b6f4fe8fd136e80c44 to your computer and use it in GitHub Desktop.
demo of struct copying
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 <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <math.h> | |
#include <iostream> | |
#include <vector> | |
#include <fstream> | |
#include <sstream> | |
#include <string> | |
using namespace std; | |
// compile: g++ strct_test.cpp -o outfile.exe | |
// #include <string> | |
struct Holder{ | |
vector <int> sequence ; | |
Holder(int tadd){ | |
for (int i = 0; i < tadd; ++i) | |
{ | |
sequence.push_back(i); | |
} | |
} | |
Holder(Holder *h, int tadd){ | |
sequence = h->sequence; | |
for (int i = 0; i < tadd; ++i) | |
{ | |
sequence.push_back(i); | |
} | |
} | |
void printit(void){ | |
printf("["); | |
for (int i = 0; i < sequence.size(); ++i) | |
{ | |
printf("%d, ", i); | |
} | |
printf("]\n"); | |
} | |
}; | |
int main(int argc, char *argv[]){ | |
Holder a = Holder(5); | |
Holder b = Holder(&a,10); | |
printf("a="); | |
a.printit(); | |
printf("b="); | |
b.printit(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment