Skip to content

Commit

Permalink
Fixed chaining_main.cpp after debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
coffee-bean committed Aug 28, 2013
1 parent c678ab6 commit 64d84ac
Showing 1 changed file with 29 additions and 12 deletions.
41 changes: 29 additions & 12 deletions chaining_main.cpp
Original file line number Diff line number Diff line change
@@ -1,46 +1,63 @@
#include <iostream.h>
#include <string.h>
#include <iostream>
#include <string>
#include <cassert>
using namespace std;

class Container
{
union
{
string str;
int val;
};
bool is_val;
private:
string str;
int val;
bool is_string;

public:
Container(string str);
Container(int val);

Container chain(int val);
operator string();
};

Container::Container(string str) : str(str), is_val(false)
Container::Container(string str) : str(str), is_string(true)
{

}
Container::Container(int val) : val(val), is_val(true)

Container::Container(int val) : val(val), is_string(false)
{

}

Container Container:chain(int val)
Container Container::chain(int val)
{
assert(!is_string);
if(this->val > val)
{
return Container("Hello");
}
else
{
return Container(val+1);
}
}

Container::operator string()
{
assert(is_string);
return str;
}

Container chain(int val)
{
return Container(val);
}

void foo(string str)
{
cout<<str<<endl;
}

int main()
{
cout<<chain(2).chain(1)<<endl;
foo(chain(2).chain(1));
}

0 comments on commit 64d84ac

Please sign in to comment.