How can I do this? I'm not even sure what the problem is so I can't really search google. Why is this not possible?:

#include <iostream>
#include <cmath>

using namespace std;

void vGameLoop();
void vDoMenu();
void vDealMenu();
void vDoDeal();

int main(){

	vGameLoop();
	return 0;
}

class CCards{
const int kiSuits = 4;
	string suits[kiSuits];
	suits[0] = "HEARTS";
}

Am I creating the class wrong?

Edited 5 Years Ago by Akill10: n/a

What are your errors? It's hard to get very specific without that information.

At first glance, though, I can see a couple things that should be addressed.

  1. You have not terminated your class declaration with a semi-colon. When you don't, it confuses the compiler.
  2. You can't initialize a member variable's value within the definition of the class. Unless the member is static (which yours currently isn't), you must do it in the class' constructor. If the variable is a constant, you need to do it in the constructor's initialization list.
  3. You are attempting to use procedural code in the definition of the class. You can't do that. A class definition can not contain any executable code. All executable code must be contained within the implementation(s) of it's member functions/methods. I suggest you have a look at this tutorial.

Edited 5 Years Ago by Fbody: n/a

Ok,Thanks for the help, but theres 1 thing I don't see explained on the cplusplus.com site. Do I only declare the function prototypes in the class definition? Then use those methods outside of the class using the scope operator?

Edited 5 Years Ago by Akill10: n/a

There are 2 ways to do it. You can do it with prototypes and implementations, or you can do it with "inline" implementations.

This is an example of prototype w/ implementation style:

//class definition
class Sample {
 private:
   const int LIMIT;  //a constant data member
   int someIntValue; //an integer data member

 public:
   Sample();         //constructor prototype
}; //<--- end Sample class definition (notice the semi-colon)

//constructor implementation
Sample::Sample() : LIMIT(5) { //constants MUST be in "initializer list"
  someIntValue = 0;           //non-constants may be handled here
}

This is an example of "inline" implementation:

//class definition
class Sample {
 private:
   const int LIMIT;      //a constant data member
   int someIntValue;     //an integer data member

 public:
   //constructor implementation serves as function prototype
   Sample() : LIMIT(5) { //constants MUST be in "initializer list"
     someIntValue = 0;   //non-constants may be handled here
   }  //end constructor implementation

}; //<--- end Sample class definition (notice the semi-colon)

Edited 5 Years Ago by Fbody: n/a

Oh wow, I didn't even see your comment that was a constructor...my bad.

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