Hey I have a fairly simple question that some quick google searches couldnt solve so I'm coming here for some help.
I'm having trouble just getting my assignment off the ground because I can't even write the skeleton code!
Basically I have a header file like so:
namespace foo{
class A {
public:
class B {
B();
int size();
const int last();
};
};
}
And I want to know how to refer to these guys outside of the file in a implementation file.
BONUS:
namespace foo{
template<typename T>
typename
class A {
public:
class B {
B();
int size();
const int last();
};
};
}
how are these functions referred to as?
Is there a formula I can follow when it comes to this or is it more of flexible, different for your needs kinda thing?
Thanks for the help!
I'm using visual studios if that changes anything...
Given:
namespace foo{
class A {
public:
class B {
B();
int size();
const int last();
};
};
}
The complete name for a function definition of size or last would be:
int foo::A::B::size() {...}
const int foo::A::B::last() {...}
Given:
namespace foo{
template<typename T>
typename
class A {
public:
class B {
B();
B & operator ++();
int size();
const int last();
template< typename I, typename R>
R getsomethingfrom( const I & );
};
};
}
The function definitions would be:
template <typename T> int foo::A<T>::B::size() { ... }
template <typename T> const int foo::A<T>::B::last() { ... }
For these, getting the pointer to a member function would be:
auto p = &foo::A<T>::B::size;
Constructor definition would be:
template<typename T> foo::A<T>::B::B() {}
Making one of these things:
foo::A<T>::B nb{}; // note, with nb() it complains
The operator function definition returning a reference to a B, in the template, tricky:
template<typename T> // standard opening template....
typename foo::A<T>::B & // the return type...needs a typename
foo::A<T>::B::operator++() // the function declaration of operation ++
{ ... return *this; } // must return *this or equivalent B&
In case you're curious, if a template function is inside B, like getsomethingfrom, then definition of the function is:
template< typename T> // class template
template< typename I, typename R> // function template
R foo::A<T>::B::getsomethingfrom( const I & ) // returns an R, takes I
{ R r{}; return r }