[sclug] Using an enum as a method return type in C++

Tim Sutton t.sutton at reading.ac.uk
Sat Oct 25 09:05:37 UTC 2003


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi

I am trying to return an enum from a method as shown in the simple example 
below. When I try to compile with kdevelop, I get the following error:

test.cpp:25: syntax error before `::' token 

Is it possible to return an enum, or do I have to return the value as an Int 
(which I dont want to do!)?

Thanks

Tim


/***************************************************************************
                          test.h  -  description
                             -------------------
    begin                : Tue May 6 2003
    copyright            : (C) 2003 by Tim Sutton
    email                : t.sutton at reading.ac.uk
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef TEST_H
#define TEST_H


/**
  *@author Tim Sutton
  */

class test {

private:

private: // Private attributes
  /**  */
      enum weekday {mon, tue, wed,thurs, fri};
  weekday day;

        
public: 
	test();
	virtual ~test();
  /** Write property of weekday day. */
  virtual void setday( const weekday _newVal);
  /** Read property of weekday day. */
  virtual const weekday getday();
};

#endif

- -----------------------------------------------------------------------------------------------------------

/***************************************************************************
                          test.cpp  -  description
                             -------------------
    begin                : Tue May 6 2003
    copyright            : (C) 2003 by Tim Sutton
    email                : t.sutton at reading.ac.uk
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#include "test.h"

test::test(){
}
test::~test(){
}
/** Read property of weekday day. */
const weekday test::getday(){
	return day;
}
/** Write property of weekday day. */
void test::setday( const weekday _newVal){
	day = _newVal;
}


- -- 
Tim Sutton
BDWorld Middleware Programmer
- -------------------------------------------------------------------
BiodiversityWorld Project
Centre for Plant Diversity & Systematics
School of Plant Sciences
The University of Reading
Reading, RG66AS, UK

Web     :   www.bdworld.org
Phone  :   +44-(0)118-378-6052  
Email    :   t.sutton [at] reading.ac.uk
(email preferred method of correspondence)
- -------------------------------------------------------------------
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)

iD8DBQE+t565Zxb+GYjbYHkRAoBeAKDqfoFF7eDoX2cmu0qdyHyPNLzs+wCfXmP/
0N3P44Cg9WTkfLkO/FnES3M=
=40xa
-----END PGP SIGNATURE-----




More information about the Sclug mailing list