im doing this example project, but i cant seem to figure out why visual studio 2008 keeps giving me error C2075-'Target of operator new()' : array initialization needs curly braces.
it says the error is on line 47
#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;
}