Skip to content
Snippets Groups Projects
Commit 7e7a031d authored by kaller01's avatar kaller01
Browse files

Midterm final questions

parent 90534322
No related branches found
No related tags found
No related merge requests found
struct Outer
{
template <typename T>
struct Inner
{
static void fun();
};
};
template <typename T>
auto call()
{
// return /* call T::inner<T>::fun() */;
// return typename T::Inner<T>::fun();
// using type = typename T::Inner<T>;
// return type::fun();
// return typename T::Inner<T>::template fun();
// return T::Inner<T>::fun(); // T::Inner is unknown, probably an int or something... So < is seen as a "less than" operator, since the compiler doesn't know Inner is a template
return T::template Inner<T>::fun();
using type = typename T::template Inner<T>;
return type::fun();
// using type = T::template Inner<T>;
// return type::fun();
// return typename T::template Inner<T>::fun();
}
int main()
{
call<Outer>();
}
#include <iostream>
int main() {
int y{1337};
int x((int) y);
std::cout << x << std::endl;
// double a = (double) y;
// double b = (double) "hej";
}
// static_cast (convert between statically known types)
// const_cast (adding or removing const-ness)
// reinterpret_cast (converting between pointer types)
\ No newline at end of file
#include <iostream>
struct A
{
virtual ~A() = default;
};
struct B : public A { };
struct C : public B { };
struct D : public A { };
A* a { new A{} };
A* b { new B{} };
A* c { new C{} };
A* d { new D{} };
int main(){
// B tmp1 = *dynamic_cast<B*>(c);
B tmp1 = *((B*) c);
std::cout << (typeid(tmp1).name()) << std::endl;
std::cout << (typeid(dynamic_cast<B*>(c)).name()) << std::endl;
std::cout << typeid(dynamic_cast<A*>(c)).name() << std::endl;
std::cout << (typeid(*dynamic_cast<B*>(c)) == typeid(*dynamic_cast<A*>(c))) << std::endl;
std::cout << dynamic_cast<B*>(c) << std::endl;
std::cout << (bool) dynamic_cast<B*>(c) << std::endl;
}
\ No newline at end of file
int& get(int val)
{
int* tmp = new int{val};
int& tmp2 = *(tmp);
return tmp2;
}
int main()
{
int& x{get(7)};
x = get(5);
delete &x;
}
\ No newline at end of file
template <typename... Ts>
auto fun(Ts... ts)
{
return ((ts, 1) + ...);
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment