#ifndef DECK_H
#define DECK_H

class Deck
	struct card{int symbol; int value;};
	card card_list[52];
	void generate_deck();
	void main();
	static int const diamond = 1;
	static int const club = 2;
	static int const heart = 3;
	static int const spade = 4;



#include "stdafx.h"
#include <cstdlib>
#include <iostream>
#include <time.h>

#include "Deck.h"

using namespace std;
void Deck::generate_deck()
	for(int array_location=0;array_location<=12;array_location++)
		card_list[array_location].symbol = diamond;
		card_list[array_location].value = array_location+1;

void Deck::main()

I get an access violation error when I try to compile and the compiler will just crash.

However, everything would work fine if I made the declaration for card card_list[52] inside the class instead of the header.

*Note : the code above is just a small part of the whole program.

Edited by rlhh: n/a

7 Years
Discussion Span
Last Post by rlhh

So the code you pasted works? Since card_list is in the class.
+ are you sure the _compiler_ is crashing?

Please give us the smallest source that reproduces the problem.. including all files that we need (e.g. the card class etc.) - then we can give better suggestions.


Sorry for any misunderstanding but what I meant was if the "struct card" and "card card_list[52]" was declared in the class, it would work.

However, both the "struct card" and "card card_list[52]" is declared in the header.(I need it in the header so that I'll be able to access the struct from a different class).

I got the access violation error when I tried running the code in debug mode(Visual Studio Express 2010). If I tried to build(ctrl + F5), the whole command prompt would just crash.


OOPS! Sorry for the mistake, I somehow got confused with compiling and running.

Yeah, it compiles just fine but it crashes while running.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.