-1

Writing a klonkide program for my final year project.

But now there was an error that had me stunned.

This is the draft for my klondike program;

// ConsoleApplication18.cpp : Defines the entry point for the console application.
//

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

using namespace std;
// Removed part

class card {
    char *rank[] = {"A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"};
    char *suit[] = {"S", "D", "H", "C"};
    char *show[] = { "Up", "Down" };

};

However, on the "*rank[]" was an error that says: "Incomplete type is not allowed". Also i get the C2011 error upon running it. Also when i tried to write the class, the chars above will start to get the Incomplete type error. Help?

Now i removed the "struct", but the incomplete type error still exists, and it now shows:

Error C2229 class 'card' has an illegal zero-sized array
Error C2997 'card::show': array bound cannot be deduced from an in-class initializer

Actually the struct was only there because of this error.

EDIT: ok. i now solved this by dictating the arrays in a way like one of the answers below. I also found another problem that will merit another question soon.

Mr-ex777
  • 19
  • 1
  • 1
  • 2
  • 6
    Err.... this is all kinds of broken. Two classes declared with the same name, but different member types? (You are aware that the only difference between `struct` and `class` is that the one is defaulting to `public` and the other to `private`? You are redefining `card`.) – DevSolar Jun 17 '16 at 13:37
  • What is "*the C2011 error*"? – melpomene Jun 17 '16 at 13:40
  • 3
    Both your types are named "card", and C2011 is "class type redefinition". What's unclear about that error? – molbdnilo Jun 17 '16 at 13:41
  • The errors are always there even if the struct does not exist. – Mr-ex777 Jun 17 '16 at 13:56
  • this has nothing to do with debugging because it doesn't even compile yet – phuclv Feb 18 '22 at 03:12

2 Answers2

0

You can't have struct card and class card at the same time.

sjsam
  • 21,411
  • 5
  • 55
  • 102
  • 2
    "Identifiers must be unique no matter the type." It is not correct statement. For example this declaration struct A {} A; is valid in C++. – Vlad from Moscow Jun 17 '16 at 13:55
0

You declared two types with the same name breaking the one definition rule.

Take into account that in C++ string literals have types of constant character arrays. Thus for example the second class should be defined like

class card {
    const char *rank[13] = {"A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"};
    const char *suit[4] = {"S", "D", "H", "C"};
    const char *show[2] = { "Up", "Down" };

};

As for the error message, the sizes of the arrays in the class definition should be specified explicitly.

Sara Fuerst
  • 5,688
  • 8
  • 43
  • 86
Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335