:) ... dude.... what do you mean by 'link classes' ?
Agni
Practically a Master Poster
655 posts since Dec 2007
Reputation Points: 431
Solved Threads: 116
You could use a std::vector, or std::list, or write your own linked list. If that isn't what you want then we have no idea what you mean.
Ancient Dragon
Retired & Loving It
30,042 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,341
> how to link classes with each other?
classes are types. are you looking for how to implement a typelist?
a tutorial introduction to typelists: http://www.ddj.com/cpp/184403813?_requestid=1305388
you might then want to read Alexandrescu's Modern C++ Design (Addison-Wesley Longman, 2001).
and look up Boost.MPL http://www.boost.org/doc/libs/1_35_0/libs/mpl/doc/index.html which has a ready made framework for template metaprogramming. eg.
#include <boost/mpl/vector.hpp>
#include <boost/mpl/push_front.hpp>
#include <boost/mpl/push_back.hpp>
#include <boost/mpl/replace.hpp>
#include <boost/mpl/at.hpp>
#include <boost/mpl/int.hpp>
#include <boost/mpl/assert.hpp>
class A{} ; class B{} ; class C{} ; class D{} ; class E{} ;
int main()
{
using namespace boost ;
typedef mpl::vector<A,B> seq_ab ;
typedef mpl::push_front< seq_ab, C >::type seq_cab ;
typedef mpl::push_back< seq_cab, D >::type seq_cabd ;
typedef mpl::replace< seq_cabd, B, E >::type seq_caed ;
BOOST_MPL_ASSERT(
( mpl::is_same< mpl::at< seq_caed, mpl::int_<2> >, E > ) ) ;
}
vijayan121
Posting Virtuoso
1,606 posts since Dec 2006
Reputation Points: 1,159
Solved Threads: 287
There are many classes which must be link or in other words put together in order to work as one big class.
Oh, do you mean inheritence?
class base
{
// blabla
};
class derived : public base
{
// linked (derived) class
};
Ancient Dragon
Retired & Loving It
30,042 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,341
I guess you mean
class A {
};
class B {
A a;
};
ithelp
Nearly a Posting Maven
2,230 posts since May 2006
Reputation Points: 769
Solved Threads: 128
Are we playing 'Read My Mind' here :) ...
Agni
Practically a Master Poster
655 posts since Dec 2007
Reputation Points: 431
Solved Threads: 116
Are we playing 'Read My Mind' here :) ...
In theory, if we supplied ∞ answers, the right one would be among them :)
So I'll have a look in my crystal ball and say....: Namespaces!
#include <iostream>
namespace ClassSpace
{
class a
{
public:
a() { std::cout << "Created A\n";}
~a(){ }
};
class b
{
public:
b(){ std::cout << "Created B\n";}
~b(){}
};
}
int main()
{
ClassSpace::a Ca;
ClassSpace::b Cb;
std::cin.get();
return 0;
}
Nick Evan
Not a Llama
10,112 posts since Oct 2006
Reputation Points: 4,142
Solved Threads: 403
That's true.. but what i meant was that may be the OP could tell us if either of this is right or not. Or probably Mr OP you can tell us what is it that you're trying to solve and then we might be able to point in the right direction.
I dont mind these answers though, Vijayan's example is very interesting and i'm still trying to understand that :) ...
Agni
Practically a Master Poster
655 posts since Dec 2007
Reputation Points: 431
Solved Threads: 116