Thread: polymorphism with vars?

  1. #1
    Alessio Stella
    Join Date
    May 2008
    Location
    Italy, Bologna
    Posts
    251

    polymorphism with vars?

    how to do something similar to what in http://cboard.cprogramming.com/showthread.php?t=109803
    "partial polymorphism"

    but this time with variables and specifically with enum
    I want a var to be enum and have certain values defined for a base class while other values predefined in the base class and redefined by derived classes

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    What is the purpose of this enum?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    I don't think you can do what you want exactly - but if you describe better what you are trying to do, perhaps we can help you with a solution.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  4. #4
    Alessio Stella
    Join Date
    May 2008
    Location
    Italy, Bologna
    Posts
    251
    well i have different stations with parameters that can be written or read
    there is a set of parameters which is common to all stations
    other parameters instead are specific for each station

    i need an uint index to identify which parameter to read (or write) upon request
    i need this index to be for instance of kind enum with a base set for the common indexing and a derived specific set of values for the specific indexing

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by mynickmynick
    well i have different stations with parameters that can be written or read
    there is a set of parameters which is common to all stations
    other parameters instead are specific for each station
    I am afraid that I do not quite understand what is a "station" and what is a "parameter", and how they are related. When you say that you have different stations, do you mean that you have different station objects, or that you have different station subtypes?

    Quote Originally Posted by mynickmynick
    i need an uint index to identify which parameter to read (or write) upon request
    i need this index to be for instance of kind enum with a base set for the common indexing and a derived specific set of values for the specific indexing
    Let's not go into implementation detail so soon. What is a "request"? Who will be making such a request?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  6. #6
    Alessio Stella
    Join Date
    May 2008
    Location
    Italy, Bologna
    Posts
    251
    Here follows what the code i am writing looks like
    Station is a Vision System with one or more cameras
    parameters are image processing parameters or camera parameters

    Code:
    typedef class c_StationParameters
    {
    public:
    	Type_StationArgs * Args;
    	unsigned int ToBeSaved;//periodically checked. If ==1 old parameters are backupped, new parameters are saved then this bool is reset
    	MUTEX  ReadImageMutex;
    	//List of Station non specific parameters (they can have different values for every station but there type is the same for all)
    	float MaxProcessingMsec;	float MaxProcessingMsecRI;
    	
    	//..other parameters to be added here
    	//..
    	
    	//METHODS
    	virtual ~c_StationParameters(){};
    	
    	//General methods
    	int LoadStationParameters( unsigned int Backup);
    	int CheckStationParameters(); //to be rewritten like Load with the non virtual interface
    	int SaveStationParameters();
    	int UpdateStationParametersReadImage();
    	
    	//Specific methods
    	virtual int LoadStationSpecificParameters( FILE  *ParFile)=0;//{printf("Calling wrong method!! ######################\n");return(0);};
    	virtual int CheckStationSpecificParameters()=0;
    	virtual int BackupStationSpecificParameters(FILE  *ParFile, FILE  *ParFile_BP)=0;//{return(0);};
    	virtual int SaveStationSpecificParameters(FILE  *ParFile)=0;//{return(0);};
    	virtual int UpdateStationSpecificParametersReadImage()=0;
    	
    } ALIGN Type_StationParameters;
    
    
    
    typedef class c_Station1_Parameters : public c_StationParameters
    {//this part is strictly station dependent
    
    public:	
    
    	
    
    	
    	virtual int LoadStationSpecificParameters(  FILE  *ParFile);
    	virtual int CheckStationSpecificParameters();
    	virtual int BackupStationSpecificParameters(FILE  *ParFile, FILE  *ParFile_BP);
    	virtual int SaveStationSpecificParameters(FILE  *ParFile);	
    	
    public:
    	//first image processing parameters
    	//0...1024
    	float Img1RulerX;  float Img1RulerXRI;
    
    	
    	//second image processing parameters
    	//0...1024
    	float Img2RulerX;  float Img2RulerXRI;
    
    	
    	//Processing parameters
    	//0...2048
    	float PacketAngleTolerance; float PacketAngleToleranceRI;
    
    
    } ALIGN Type_Station1_Parameters;
    Last edited by mynickmynick; 01-07-2009 at 03:51 AM.

  7. #7
    Alessio Stella
    Join Date
    May 2008
    Location
    Italy, Bologna
    Posts
    251
    RI="ReadImage"
    Of each parameter is made periodically a Read Copy so that each parameter has one copy used only by the station and another copy shared between the Station thread and the socket server thread for read requests (protected by ReadImageMutex)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Polymorphism - "pointers" or "references"?
    By Petike in forum C++ Programming
    Replies: 10
    Last Post: 06-04-2009, 05:06 PM
  2. A C++ program examples showing Polymorphism, please help.
    By MarkSquall in forum C++ Programming
    Replies: 19
    Last Post: 06-06-2008, 04:41 AM
  3. Polymorphism
    By GiN0 in forum C++ Programming
    Replies: 1
    Last Post: 03-23-2007, 06:18 PM
  4. change sorting method using polymorphism
    By Forever82 in forum C++ Programming
    Replies: 2
    Last Post: 07-31-2003, 01:21 PM
  5. Polymorphism & Overloaded Operators :: C++
    By kuphryn in forum C++ Programming
    Replies: 2
    Last Post: 09-13-2002, 08:40 PM