CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Threaded View

  1. #1
    Join Date
    Apr 2009
    Posts
    38

    Setting function return type

    I want my function to return the type mpz_t, but I'm not sure how?

    I've tried:
    mpz_t MyFunction(mpz_t A, mpz_t B){}

    But it didn't work, here is my code so far, I have bolded the parts of the code which are causing errors and added the errors in the comments:

    Code:
    #include <iostream>
    #include <mpir.h>
    
    using namespace std;
    
    ???? A(mpz_t m, mpz_t n){
    	mpz_t mmo; //used to store the value of m, minus one
    	mpz_t nmo; //used to store the value of n, minus one
    	mpz_t one; //used to store the value 1
    	mpz_init(mmo);
    	mpz_init(nmo);
    	mpz_init(one);
    	mpz_set_ui(one, 1);
    
    	if(mpz_cmp_ui(m, 0) == 0){
    		mpz_add_ui(n, n, 1);
    		return n; //error: return value type does not match the function type
    	}
    
    	if(mpz_cmp_ui(m, 0) > 0 && mpz_cmp_ui(n, 0) == 0){
    		mpz_sub_ui(mmo, m, 1);
    		return A(mmo, one);
    	}
    
    	if(mpz_cmp_ui(m, 0) > 0 && mpz_cmp_ui(n, 0) > 0){
    		mpz_sub_ui(mmo, m, 1);
    		mpz_sub_ui(nmo, n, 1);
    		return A(mmo, A(m, nmo)); 
    	}
    }
    
    int main(){
    	mpz_t param1;
    	mpz_init(param1);
    	mpz_t param2;
    	mpz_init(param2);
    
    	mpz_set_ui(param1, 4);
    	mpz_set_ui(param2, 2);
    
    	mpz_out_str(stdout, 10, A(param1, param2)); 
    	return 0;
    }
    Is there a way around this?

    Thank you
    Last edited by SamstaUK; May 28th, 2012 at 06:00 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured