> For the complete documentation index, see [llms.txt](https://docs.applayer.com/testnet/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.applayer.com/testnet/evm-contracts/cpp-to-other-contract-calls.md).

# C++ to other contract calls

The `ContractHost` class employs templated functions to support flexible and efficient interaction with contracts. These templates enable passing any combination of arguments and return types (including `void`) to and from other types of contracts. This use of templates helps to leverage the fast ABI encoding/decoding processes, ensuring optimal performance and flexibility during contract execution:

```cpp
template <typename R, typename C, typename... Args>
R callContractViewFunction(
  const BaseContract* caller, const Address& targetAddr,
  R(C::*func)(const Args&...) const, const Args&... args
) const;

template <typename R, typename C, typename... Args>
R callContractFunction(
  BaseContract* caller, const Address& targetAddr,
  const uint256_t& value,
  R(C::*func)(const Args&...), const Args&... args
);
```

This approach allows for dynamic interaction with contracts without pre-defining all possible function signatures, accommodating various contract behaviors and states dynamically.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.applayer.com/testnet/evm-contracts/cpp-to-other-contract-calls.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
