954,153 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

SMS(student managent system)

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

WondererAbu
Newbie Poster
4 posts since Apr 2008
Reputation Points: 10
Solved Threads: 0
 

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

WondererAbu
Newbie Poster
4 posts since Apr 2008
Reputation Points: 10
Solved Threads: 0
 
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
Team Colleague
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
Banned
2,230 posts since May 2006
Reputation Points: 769
Solved Threads: 128
 

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

RenjithVR
Light Poster
41 posts since Mar 2008
Reputation Points: 12
Solved Threads: 7
 

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
Moderator
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
 

WonderAbu have no idea how to ask, and you guys answer quite advanced things. All I could advise is to check out some basics and terminology in C++:
http://en.wikipedia.org/wiki/Object_oriented_programming
http://en.wikipedia.org/wiki/C%2B%2B

Available in other languages as well!

Cybulski
Light Poster
47 posts since Apr 2008
Reputation Points: 15
Solved Threads: 3
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You