Thread: static casting problem

  1. #1
    Registered User
    Join Date
    Mar 2002
    Posts
    22

    static casting problem

    hey every1
    slight problem with casting if u could spare the time to have a quick look and c wat is going wrong
    thanks alot
    Code:
    class JppVariable{
    public:
    	string name;
    	string type;
    };
    class JppSimple: public JppVariable{
    public:
    	int simple;
    	JppSimple(string _name, string _type, int _value);
    };
    JppSimple::JppSimple(string _name, string _type, int _value){
    	name = _name;
    	type = _type;
    	simple = _value;
    		 
    }
    //small but simple inheritance tree
    //later i try this
    
    vector <JppVariable> Variables;
    JppSimple test = JppSimple("anything", "SIMPLE", 5);
    Variables.push_back(test);
    
    JppSimple temp = static_cast<JppSimple>(Variables[0]);
    i thought that this should work but i get two errors:
    error C2440: 'static_cast' : cannot convert from 'class JppVariable' to 'class JppSimple'
    error C2512: 'JppSimple' : no appropriate default constructor available
    can anyone tell me where i am going wrong
    thanks for your time
    rxg00u

  2. #2
    Registered User
    Join Date
    Dec 2001
    Posts
    479
    what does this part do:

    class JppSimple:

    maybe u ment class JppSimple
    {
    //or...
    //...i dont know
    }

  3. #3
    Registered User
    Join Date
    Mar 2002
    Posts
    22

    im not sure

    sorry but im not sure i know what u mean?
    ClassJppsimple extends JppVaraible and has the paramerters shown above and the constructor above sorry if this is not what you meant.
    rxg00u

  4. #4
    Registered User
    Join Date
    Dec 2001
    Posts
    479
    send your entire code i think i know the problem (if u havent solved it yet)
    please let me know if u have

  5. #5
    Registered User
    Join Date
    Mar 2002
    Posts
    22
    hi soory for disturbing u ,
    however i hav not solved it but i have approached it a diffrent way i now am using pointers to store in my vector for some reason casting pointers works better than casting actual objects ( do u know a reason for this as it would be a good bit of knowledge), anyway thanks for ur time and all ur help
    yours pants
    (rxg00u)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 03:06 PM
  2. Templates from DLL or static library problem
    By mikahell in forum C++ Programming
    Replies: 2
    Last Post: 01-01-2008, 01:49 AM
  3. get keyboard and mouse events
    By ratte in forum Linux Programming
    Replies: 10
    Last Post: 11-17-2007, 05:42 PM
  4. Problem in exporting static function in win32 dll
    By dattaforit in forum Windows Programming
    Replies: 4
    Last Post: 12-04-2006, 12:03 PM
  5. non static WndProc problem
    By aker_y3k in forum C++ Programming
    Replies: 14
    Last Post: 10-03-2002, 02:07 PM