Skip to content

Instantly share code, notes, and snippets.

@zafarali
Created July 8, 2016 19:51
Show Gist options
  • Save zafarali/a0b4a42d453198b6f4fe8fd136e80c44 to your computer and use it in GitHub Desktop.
Save zafarali/a0b4a42d453198b6f4fe8fd136e80c44 to your computer and use it in GitHub Desktop.
demo of struct copying
#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