Your syntax to construct the object is correct.
It's hard to say for sure since you haven't told the error, but my guess is that your problem is that the constructor is private. That means you cannot use the constructor outside the class.
Edit concerning the error message:
Here's a complete example that compiles. I've added some example lines that would produce the error: no matching function for call to 'Foo::Foo()'.
#include <string>
class Foo{
public:
Foo(std::string str, int nbr);
};
// empty definition
Foo::Foo(std::string str, int nbr) {}
// delegating constructor (c++11 feature)
// this would produce error: no matching function for call to 'Foo::Foo()'
//Foo::Foo(std::string str, int nbr) : Foo::Foo() {}
int main() {
Foo* myFoo;
myFoo = new Foo("testString", -1); // this is correct
// trying to construct with default constructor
//Foo myFoo2; // this would produce error: no matching function for call to 'Foo::Foo()'
//Foo* myFoo3 = new Foo(); // so would this
}
Given the error, your code is trying to use the default constructor somewhere.
Edit2 concerning your new Foo2
example. Your declaration of Foo* and the call to the constructor are still correct and the code should compile if you fix the method visibility and missing semicolons. Following example compiles:
#include <string>
class Foo{
public:
Foo(std::string str, int nbr); // Overloaded constructor
};
Foo::Foo(std::string str, int nbr){}
class Foo2{
Foo* myFoo; // This is still correct
public:
Foo2() {
myFoo = new Foo("", 1);
}
};
int main() {
Foo2 foo2;
}