i was giving an assignemnt to show stacks with out using the STL .
my question is is my code a correct example or not ?
and if so can some some one guide or explain to me what i did wrong or what i need to change
#include <stdio.h>
#include <string>
#include <vector>
class Foo
{
std::string _str;
public:
Foo(void)
{
printf("Foo: Void constructor\n");
_str = "";
}
Foo ( const char *s )
{
printf("Foo: Full constructor [%s]\n", s);
_str = s;
}
Foo( const Foo& aCopy )
{
printf("Foo: Copy constructor\n");
_str = aCopy._str;
}
virtual ~Foo()
{
printf("Foo: Destructor\n");
}
Foo operator=(const Foo& aCopy)
{
_str = aCopy._str;
return *this;
}
std::string String()
{
return _str;
}
void setString( const char *str )
{
_str = str;
}
};
int main()
{
printf("Creating array via new\n");
Foo *f = new Foo[2];("Hello");// line 47
printf("Creating array on heap\n");
Foo f1[3];
// Create a vector
printf("Creating vector of foo\n");
std::vector<Foo> fooVector;
printf("Adding objects to vector\n");
Foo f2;
Foo f3;
Foo f4;
fooVector.insert( fooVector.end(), f2 );
fooVector.insert( fooVector.end(), f3 );
fooVector.insert( fooVector.end(), f4 );
printf("Deleting array on heap\n");
delete [] f;
}