6 Replies - 843 Views - Last Post: 24 March 2013 - 07:49 AM Rate Topic: -----

#1 theindianhippy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 08-March 13

How to pass an enum argument from private to main

Posted 20 March 2013 - 11:27 AM

Hey guys I'm having trouble calling a function which has an Enum parameter. I have defined the enum datatype in Private section of the class and then I'm trying to pass that value to function in the main. I'll post the code below.

Pizza.h

#ifndef Pizza_h
#define Pizza_h

class Pizza
{
private:
	enum Size {S,M,L};
	enum Type {R,V,C};
	Size s;
	Type t;

public:
        Pizza ();
		void setSize(Size x);
		void setType(Type y);
        int getSize ();
        int getType();
        void print ();
};

#endif



Functions which I want to pass

void Pizza::setSize (Size x)
{
        Size s = x;
}
void Pizza::setType(Type y)
{
        Type t = y;
}





My main

#include <iostream>
#include <fstream>
#include "Pizza.h"
using namespace std;
void main ()
{
enum Size {S,M,L};
enum Type {R,V,C};
Pizza p;
p.print();
Pizza *x = new Pizza;
x->print();
p.setSize(M);<----- ERROR
p.setType®;<----- ERROR
p.print();

}

My main

#include <iostream>
#include <fstream>
#include "Pizza.h"
using namespace std;
void main ()
{
enum Size {S,M,L};
enum Type {R,V,C};
Pizza p;
p.print();
Pizza *x = new Pizza;
x->print();
p.setSize(M);<----- ERROR 
p.setType®;<----- ERROR
p.print();

} 




Is This A Good Question/Topic? 0
  • +

Replies To: How to pass an enum argument from private to main

#2 theindianhippy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 08-March 13

Re: How to pass an enum argument from private to main

Posted 20 March 2013 - 11:42 AM

Never mind guys, fixed it :D

Had to declare the enums outside private. How stupid of me.
Was This Post Helpful? 0
  • +
  • -

#3 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2998
  • View blog
  • Posts: 10,380
  • Joined: 08-August 08

Re: How to pass an enum argument from private to main

Posted 20 March 2013 - 01:01 PM

What's with void main ()? It's int main()!
Was This Post Helpful? 0
  • +
  • -

#4 theindianhippy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 08-March 13

Re: How to pass an enum argument from private to main

Posted 23 March 2013 - 03:36 AM

Not necessarily, void main () works just fine. The only difference is that I don't have to return a value in the end to check if my program works correctly or not.

However I'm not sure, just a beginner at all this. Feel free to correct me if I'm wrong :D
Was This Post Helpful? 0
  • +
  • -

#5 snoopy11  Icon User is online

  • Engineering ● Software
  • member icon

Reputation: 801
  • View blog
  • Posts: 2,357
  • Joined: 20-March 10

Re: How to pass an enum argument from private to main

Posted 23 March 2013 - 04:20 AM

View Posttheindianhippy, on 23 March 2013 - 10:36 AM, said:

However I'm not sure, just a beginner at all this. Feel free to correct me if I'm wrong :D/>/>


He just did, listen to him
Take good advice when it's offered especially from an esteemed member like CTphpnwb

Snoopy.

This post has been edited by snoopy11: 23 March 2013 - 04:20 AM

Was This Post Helpful? 0
  • +
  • -

#6 theindianhippy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 08-March 13

Re: How to pass an enum argument from private to main

Posted 24 March 2013 - 07:41 AM

View Postsnoopy11, on 23 March 2013 - 04:20 AM, said:

View Posttheindianhippy, on 23 March 2013 - 10:36 AM, said:

However I'm not sure, just a beginner at all this. Feel free to correct me if I'm wrong :D/>/>/>


He just did, listen to him
Take good advice when it's offered especially from an esteemed member like CTphpnwb

Snoopy.


But why am I wrong? I need a reason rather than just telling me that I'm wrong. It's like saying a priest saying that there's a GOD but without any reason.
Was This Post Helpful? 0
  • +
  • -

#7 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2998
  • View blog
  • Posts: 10,380
  • Joined: 08-August 08

Re: How to pass an enum argument from private to main

Posted 24 March 2013 - 07:49 AM

It's in the standard.
http://en.wikipedia....n_(programming)

If you use void main() in a course you can expect to lose points. If you use it for a paying job you can expect to lose money.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1