Calling Constructor without a pointer

How exactly do I call the constructor of a class without making it a pointer and using the new keyword?

Am I unable to do this without making it a pointer?
Last edited on
You've asked an odd question.
1
2
3
4
struct my_class
{
  my_class( const std::string& s, int n ) { ... };
};
 
my_class my_object( "Hello", -7 );

Perhaps if you tell us what exactly it is you are trying to do...
At risk of repeated Duthoshas' information, any time you create an instance of a class (or struct), the constructor is called.

Like this:

someClass anInstance;

That called the constructor of someClass, and as you can see, no pointers or news to be seen.
Basically I have this Animation class that I'm using for a game and I've created a variable of it in a header file:
 
Animation animation;

I'm then doing what you mentioned in the source file:
 
Animation animation(this, 0.5f);

but despite doing that, I still get this error that "No default constructor exists"
In the header, use a declaration: extern Animation animation;

In the implementation file (.cpp), define it: Animation animation(thisxxx, 0.5f);
Note: we can use the keyword this only in non-static member functions.
Topic archived. No new replies allowed.