class Movie{
private:
string director,title,genre;
public:
Movie(){
director="";title="";genre="";}

int main(){
Movie a();}

I am having problems with my default constructor. my program compiles but it gives me a warning "warning C4930: 'Movie a(void)': prototyped function not called (was a variable definition intended?)" and if i try to run say d.setTitle("test"); it gives me an error of class/struct....what am i missing? i have been staring at this for hours now.

class Movie{
private:
string director,title,genre;
public:
Movie(){
director="";title="";genre="";}
};

int main(){
Movie a();}

yea i have that i just forgot to type it....i paraphrased and just forgot to type it in

like i said the program all compiles correctly it just gives me a warning about the default constructor and i wanted to know why

It is because you are not calling the default constructor.

Use Movie a; (without parentheses).

I can't remember the reason for this, but I've read it somewhere. Give me a minute to look it up.

class Movie{
private:
string director,title,genre;
public:
Movie(){
director="";title="";genre="";}

int main(){
Movie a();}

I am having problems with my default constructor. my program compiles but it gives me a warning "warning C4930: 'Movie a(void)': prototyped function not called (was a variable definition intended?)" and if i try to run say d.setTitle("test"); it gives me an error of class/struct....what am i missing? i have been staring at this for hours now.

I think its happening because you're not declaring and independent variable of type Movie. if you say 'Movie a' instead of 'Movie a()' you will not get that warning.

A little googling answered it. The reason is that myclass foo(); is a function prototype...

but myclass foo( 12 ); is not...

duh
/me slaps head :$

Hope this helps. :)

Oh, yeah, almost forgot. Initialize your constructors this way:

class Movie {
  private:
    string director,title,genre;
  public:
    Movie(): director(""), title(""), genre("") {}
  };

int main(){
  Movie a;
  }

Read why here.

Have fun!

class Movie
{
private:
string director,title,genre;
public:
Movie()
{
director="";title="";genre="";
}
};// u r making a class so u have to close it as well
int main()
{
Movie a;//for an object there is no need of paranthesis
return 0;
}
#include<iostream>
#include<string>

using namespace std;

class Movie
{
private:
string director,title,genre;
public:
Movie()
{
director="";
title="";
genre="";
cout<<"in constructor\n";
}
};

int main()
{
Movie a;
return 0;
}

This works fine but ..... Movie a(); not works... This is becoz like int xyz(); and int xyz; both are different is it.. like wise Movie a; and Movie a(); are both different..... int xyz(); is a prototype of function xyz().. but int xyz; is variable xyz or object xyz... like wise only what stroustoup did for a class and object also.... hope u understood... thank u :-)

#include<iostream>
#include<string>

using namespace std;

class Movie
{
private:
string director,title,genre;
public:
Movie()
{
director="";
title="";
genre="";
cout<<"in constructor\n";
}
};

int main()
{
Movie a;
return 0;
}

This works fine but ..... Movie a(); not works... This is becoz like int xyz(); and int xyz; both are different is it.. like wise Movie a; and Movie a(); are both different..... int xyz(); is a prototype of function xyz().. but int xyz; is variable xyz or object xyz... like wise only what stroustoup did for a class and object also.... hope u understood... thank u :-)

see let me explain u . the thing is
when we declare a variable we write it something like this int xyz;
int is its data type
like wise when we declare an object it is something like this
class name and some variable..
eg: movie a;
movie is its datatype

yeah int xyz(); and int xyz; are different
int xyz();//its a prototype of a function
int xyz()// its a definition of a function
{
}

xyz();// its a call which we usually gives from main...
hope u get it:)

This article has been dead for over six months. Start a new discussion instead.