Question: I have a class called ReadFile which has a ReadFile function which then called another two methods which return the elements and numbers. How can I get these values from the ReadFile class in order for me to pass to the methods in main class?

```
public static void main(String[] args)  {

        List<Integer> numbers = new ArrayList<>();
        List<Integer> elements = new ArrayList<>();

        ReadFile numbersFile = new ReadFile();
        numbersFile.readFile();

        preSortedList(numbers, elements);

        System.out.println();
        sortedList(numbers, elements);

} 

public class ReadFile {

   public void readFile(){

        File folder = new File("/Users/Mary/NetBeansProjects/Testing/src/program/pkg4/Input");

        for (File file : folder.listFiles()) {
            try{
                FileReader fileReader = new FileReader(file);
                BufferedReader reader = new BufferedReader(fileReader);

                List<Integer> elements = getElements(reader);
                List<Integer> numbers = getNumbers(reader, elements);

                reader.close(); 
            }catch(IOException e){
                System.out.println("ERROR: There was a problem reading the file.\n" + e.getMessage());
            }  
        }
    }      

    public static List<Integer> getElements(BufferedReader reader) throws IOException{
        List<Integer> elements = new ArrayList<>();
        String numberOfElement = reader.readLine();
        elements.add(Integer.parseInt(numberOfElement));
        return elements;
    }

    public static List<Integer> getNumbers(BufferedReader reader, List elements) throws IOException{
        List<Integer> numbers = new ArrayList<>();
        String line = reader.readLine();                  
        for (String s : line.split("\\s+")) {                        
            numbers.add(Integer.parseInt(s));
        }    
        return numbers;
    } 
}

```

Answer: 
Here's a complete example using the approach Ralf wrote in #1. You can use pure C/C++ function pointers here, although you can do more complex things with C++11. 

```
#include<RcppArmadillo.h>

// [[Rcpp::depends(RcppArmadillo)]]

typedef arma::mat (*functype)(arma::mat&);

arma::mat f1(arma::mat& a){
  return a+1;
}

arma::mat f2(functype g, arma::mat a){
  return g(a);
}

//[[Rcpp::export]]
arma::mat f3(arma::mat a){
  return f2(f1, a);
}

```

R side:

```
> f3(matrix(1))
     [,1]
[1,]    2

```
The error message says all there is: To C++ `f1` is a function that expects an `arma::mat` as argument and returns an `arma::mat`. This is quite different from an `Rcpp::Function`, which is a thin wrapper around a R function. I see three possibilities:

1. Write an alternative `f2` function which expects a function pointer or `std::function` (requires C++11) with appropriate arguments.
2. Add an argument of type `Rcpp::Function` to `f3` which is used in the call to `f2`.
3. Get an appropriate R function with `Rcpp::Environment` and `Rcpp:Function`.

Without further information about the use case it is difficult to offer more advice.