Thread: va_list 's

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    3

    va_list 's

    I simply can't figure them out.

    Please don't criticize my code beside the va_list stuff... it doesn't really matter to me.

    This is in a template class (template <int N>):
    Code:
    CPolygon (CVertex first, ...)
    	{
    		if (N <= 0)
    		{
    			m_iNumVertices = 0;
    
    			return;
    		}
    
    		m_iNumVertices = N;
    
    		m_Vertices[0] = first;
    
    		va_list args;
    		va_start (args, first);
    
    		for (int i = 1; i < m_iNumVertices; i++)
    			m_Vertices[i] = (CVertex) va_arg (args, CVertex);
    
    		va_end (args);
    	}

    &#91;code]&#91;/code]tagged by Salem

  2. #2
    Registered User
    Join Date
    Sep 2002
    Posts
    417
    code tags...

  3. #3
    Registered User
    Join Date
    Oct 2002
    Posts
    3
    sorry, do you mean html tags?
    Last edited by Patrick; 10-30-2002 at 11:24 PM.

  4. #4
    Registered User
    Join Date
    Sep 2002
    Posts
    272
    Try something like -

    Code:
    #include <cstdio>
    #include <cstdarg>
    
    template <int N>
    class CInt
    {
    private:
    	int m_iNumInts;
    	int m_Ints[50];
    public:
    	CInt<N>(int first, ...)
    	{
    		m_iNumInts = N;
    				
    		va_list args;
    		va_start (args, first);
    
    		for (int i = 0; i < m_iNumInts; i++)
    		{
    			m_Ints[i] = first;
    			first = va_arg (args, int);
    		}
    
    		va_end (args);
    	}
    
    };
    Joe

  5. #5
    Registered User
    Join Date
    Oct 2002
    Posts
    3
    Well, originally, this is how I was testing it.

    I know it looks bad, but it's all part of my scheme of things.

    CPolygon <2> test (CVertex (CFloat3f (1, 1, 1)), CVertex (CFloat3f (10, 10, 10)));

    That did NOT crash (as opposed to my next test), but didn't work.

    Now, this crashes:

    CVertex verts[2];
    verts[0].SetPosition (CFloat3f (1, 1, 1));
    verts[1].SetPosition (CFloat3f (10, 10, 10));

    CPolygon <2> test (verts[0], verts[1]);

Popular pages Recent additions subscribe to a feed