logo
down
shadow

Two template classes use each other as template argument


Two template classes use each other as template argument

By : benekk
Date : January 12 2021, 09:11 PM
wish helps you Two template classes can use each other as template argument, but if I use anything defined in one class scope, it cannot be compiled. , gcc's error message is much more informative:
code :
t.C:8:5: error: need ‘typename’ before ‘A::pointer’ because ‘A’ is a dependent scope
    8 |     A::pointer pa;
      |     ^
      |     typename 
template<class B> struct A {
    typedef A *pointer;
};
template<class A> struct B {
    //typedef A::pointer APtr;
    //using APtr = A::pointer;
    //APtr pa;
    typename A::pointer pa;
};

struct AA;
struct BB;
struct AA : public A<BB> {};
struct BB : public B<AA> {};


Share : facebook icon twitter icon
Why the template with default template arguments can't be used as template with less template argument in Template Templ

Why the template with default template arguments can't be used as template with less template argument in Template Templ


By : user3277441
Date : March 29 2020, 07:55 AM
it helps some times From the standard (see 14.3.3 paragraph 1 - [temp.arg.template):
use of class template requires template argument list, nested classes

use of class template requires template argument list, nested classes


By : Milan Lama Sindhuli
Date : March 29 2020, 07:55 AM
hop of those help? I'm trying to implement by own generic/template ArrayList and I've run into a snag. I know the error comes from not having somewhere in the argument list but for me I can't figure it out here, I get a different error if I do. For brevity I've removed functions I'm unable to debug until this one is debugged first. , Try this:
code :
template <class T> 
typename ArrayList<T>::Node* ArrayList<T>::Node::getNext()
{
    return this->next;
}
template <class T> 
auto ArrayList<T>::Node::getNext() -> Node*
{
    return this->next;
}
How to declare a template function taking a template template parameter with a known template argument type?

How to declare a template function taking a template template parameter with a known template argument type?


By : Nivag1288
Date : March 29 2020, 07:55 AM
around this issue I have the following two functions: , In C++11, you can use a variadic template template parameter:
code :
template <template<typename...> class T>
void SpitLeaves(std::string & sdata, T<Leaf> const & leaves)
template <template<typename...> class T, typename... TX>
void SpitLeaves(std::string & sdata, T<Leaf, TX...> const & leaves)
Why does template argument deduction/substitution fail with std::tuple and template derived classes?

Why does template argument deduction/substitution fail with std::tuple and template derived classes?


By : Thanawach Nilnarong
Date : March 29 2020, 07:55 AM
help you fix your problem Deduction doesn't work this way. It pulls in before any conversion or whatever. Here the compiler expects a Base from which to deduce T and you are trying to pass a DerivedN. They are completely different beasts from the point of view of the type system and the function is discarded when trying to find a good match for the call.
Look at the error, it's quite clear.
code :
#include<type_traits>

// ...

template<template<typename> class C1, template<typename> class C2, typename T1, typename T2>
std::enable_if_t<(std::is_base_of<Base<T1>, C1<T1>>::value and std::is_base_of<Base<T2>, C2<T2>>::value)>
function(std::tuple<C1<T1>&, C2<T2>&> arg)
{
    std::cout << "Hello\n";
}

// ...
How can a recover the non-typename template argument from each type in a variadic pack of template classes?

How can a recover the non-typename template argument from each type in a variadic pack of template classes?


By : Aman
Date : March 29 2020, 07:55 AM
Does that help
For clarification what I am trying to accomplish is recovering the template arguments from one template class to use them in another. Below are three template classes: MyObject, MyTuple, MyPack. MyTuple takes MyObject objects as its template parameters. I want to recover the MyObject template parameters to use as the template argument for a MyPack object.
code :
template <typename>
struct getMyPack;

template <template <typename...> class C,
          template <int> class ... Cs, int ... Is>
struct getMyPack<C<Cs<Is>...>>
 { using type = MyPack<Is...>; };
#include <type_traits>

template <int>
struct MyObject1
 { };

template <int>
struct MyObject2
 { };

template <int...>
struct MyPack
 { };

template <typename...>
struct MyTuple
 { };

template <typename>
struct getMyPack;

template <template <typename...> class C,
          template <int> class ... Cs, int ... Is>
struct getMyPack<C<Cs<Is>...>>
 { using type = MyPack<Is...>; };


int main ()
 {
   using T0 = MyTuple<MyObject1<1>, MyObject2<2>, MyObject1<3>>;
   using T1 = MyPack<1, 2, 3>;
   using T2 = typename getMyPack<T0>::type;

   static_assert( std::is_same<T1, T2>::value, "!" );
 }
Related Posts Related Posts :
  • Why am I not getting any output, for my code on insertion in linked list?
  • What is the correct way of implementing this custom priority_queue
  • Unable to set the location for input in vertex shader
  • Qt: How to Access Inherited Widget?
  • Why same char is not equal
  • Why does using a range for loop gives different output than using a regular for loop in this scenario?
  • Binary tree coding problems with c++?
  • How to safely change the type of a pointer
  • Could this publish / check-for-update class for a single writer + reader use memory_order_relaxed or acquire/release for
  • Passing a function identifier as an rvalue reference and applying std::move() to it
  • The conditional operator is not allowing the program to terminate
  • Define a c++ string as "\"
  • memcpy on __declspec naked returns unexpected bytes
  • What is the proper way to link enums with CMake?
  • is it safe to use the same mutex with lock_gard and without it in other parts of code
  • How to decode MAP Invoke messages using asn1c generated code
  • How do you write multiple lines in a .txt with recursion?
  • Member function with strange type causing callback function mismatch
  • Visual Studio optimisations break SDL graphical output
  • How to use less memory in Sieve_of_Eratosthenes
  • Covariance in Callback Parameters C++
  • switch may fall through (no it may not)
  • Compilation fails calling Cocoa function from C++
  • How to handle classes with differently named member functions in algorithms?
  • Convert QString to QJsonArray
  • Data exchange finished in CPropertyPage::OnOK?
  • Template member specialization in template class
  • Is it not possible to assign a struct to an index of a vector?
  • Why is empty unordered_map.find not returning end()?
  • Template argument deduction for inheriting specializations
  • dlopen undefined reference
  • Member function of class with template arguments and default arguments outside class
  • Is it possible to implement a non-owning "slightly smart" pointer on top of standard weak pointers?
  • how to configure the AcquireCredentialsHandleA correctly
  • Using private versions of global extern variables with OpenMP
  • Eigen Block wrong amount of columns and rows
  • Memory alignment rules in inheritance
  • Is nullptr falsy?
  • tm_wday returns a large integer outside 0-6 range
  • Scope a using declaration, inside a header
  • How to specify constructor's template arguments inside a new expression?
  • Avoid allocating in constructor or preserve simplicity (and RAII?)
  • Can C++ raise an error when std array initialization is too small?
  • Reference to end is ambiguous
  • Problem with basic usage of std::enable_if
  • How to print out a decimal number as octal number using setiosflags in C++
  • Open Visual Studio with solution and specific file and line
  • Enum value based on template type
  • Is there any way to swap nodes in std::list?
  • How to copy QString into wchar_t buffer
  • Make the compiler generate an empty default function for an std::function
  • Insert or push_back to end of a std::vector?
  • Best practice for const temporary types
  • Include CSV File in Complied Binary
  • Issue with binding non static function to callback
  • How can read from some files and write content of them with different form into files with same names
  • Why does auto deduce this variable as double and not float?
  • no instance of overloaded function "std::make_unique" matches the argument list, but works with unique_ptr con
  • How to see array size from a pointer in c++
  • Error taking address of temporary in Eclipse
  • shadow
    Privacy Policy - Terms - Contact Us © festivalmusicasacra.org