:S Can you explain me how to link classes with each other?

Recommended Answers

All 11 Replies

:) ... dude.... what do you mean by 'link classes' ?

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.

> 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 > ) ) ;
}

:) ... dude.... what do you mean by 'link classes' ?

There are many classes which must be link or in other words put together in order to work as one big class.

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
};

I guess you mean

class A { 

};
class B {
A a;
};

I think you are thinking about including a file in another file. Write a main function in one file and include the needed header files with that file. Also in each class include the header files they required. The below link will give you a small idea about this.
http://www.eventhelix.com/RealTimeMantra/HeaderFileIncludePatterns.htm

To compile these classes its better to use a Makefile. The following link will guide through how to write and use a Makefile.
http://www.sethi.org/classes/cet375/lab_notes/lab_04_makefile_and_compilation.html

Are we playing 'Read My Mind' here :) ...

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;
}

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 :) ...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.