I am writing a class character for an assignment. The class relates to a role playing game. I am getting an error which I don't understand. This error occurs in the default constructor of the implementation file. The dynamic help says that I created an object without creating a pointer to that object.


I am using Visual C++ .NET 2003

CharClass.cpp(8) : error C3149: 'CharClass' : illegal use of managed type 'CharClass'; did you forget a '*'?
CharClass.cpp(8) : error C2533: 'CharClass::__ctor' : constructors not allowed a return type
CharClass.cpp(8) : fatal error C1903: unable to recover from previous error(s); stopping compilation

// CharClass header
// Base class for Characters of a game

#pragma once

#using <mscorlib.dll>
using namespace System;

public __gc class CharClass
{
public:
    CharClass();
    CharClass(String *, int, bool, int);
    ~CharClass();
    void SetChar(String *, int, bool, int);
    
    //return string representation of CharClass
    String *ToString();

    // property Name
    __property String *get__Name()
    {
        return Name;
    }

    __property void set__Name(String * charName)
    {
        Name = charName;
    }

    // property charAge
    __property int get__CharAge()
    {
        return Age;
    }

    __property set__CharAge(int charAge)
    {
        Age = ( (charAge >= 16 && <= 250 ) ? charAge : 16 );
    }

    // property charHitP
    __property void set__HitPoints()
    {
        calcPoints(int charHitP);
    }

    __property int get__HitPoints()
    {
        return hitPoints;
    }

private:
    bool isCharAlive(bool alive);    //utility function to check wheter the char is alive
    int calcPoints();                

    String *Name;                    //String to store the character's name
    int Age;                        //variable to hold the character's age
    bool isAlive;                    //variable to hold character's dead or alive value
    int hitPoints;                    //variable to hold character's hit points 
}



//Implementation of CharClass

#include "stdafx.h"
#include "CharClass.h"

// default constructor
CharClass::CharClass()
{
    SetChar( "Voltor", 16, false, 50);
}

// constructor
CharClass::CharClass(String* charName, int charAge, bool alive, int charHitP)
{
    SetChar(*charName, charAge, alive, charHitP);
}

// destructor
CharClass::~CharClass(){
}

// set character to given values
void CharClass::SetChar(String* charName, int charAge, bool alive, int charHitP)
{
    Name = charName;
    Age = charAge;
    isAlive = false;
    hitPoints = charHitP;
}

String *CharClass::ToString()
{
    return String::Concat( Name, S" Age: ", Age, S" HitPoints: ", HitPoints);
}

Gah, c++.net, horrible. Much prefer pure c++.

I agree, but that doesn't help to solve the problem. I don't have that compiler so I can't help either. I think M$ rewrote all CLR libraries between .NET 2003 and 2005, so attempting to compile with 2005 if fruitless.

you forgot to terminate the definition
of the class with a ;

[/B]class __gc whatever
{
} // need a semicolon here
This article has been dead for over six months. Start a new discussion instead.