typedef

i got this code:

1
2
3
4
5
6
7
class Cell;

typedef Cell* Link; //that means that Link is equal to Cell*, right?

//blablabla...

Link& newlink() return {some_variable};


my question is, if Link is equal to Cell*, then is it awkaward to say that Link& is equal to Cell*& ? what's that mean anyway?
That code is never going to compile.
Try this instead:
1
2
3
4
5
6
Link & newlink()
{
    Link temp;
    Link &rv = temp;
    return rv;
}


Even that I'm not sure is what you want. What are you trying to do anyway? Why don't you have Cell defined? just fiddling around I suppose. I really wouldn't say that Link is equal to Cell*, but rather that Link is another way for saying Cell*. Cell*& would be an adress of a Cell pointer, I guess.

Hope I could help. (Even though I'm almost positive I didn't.)
Last edited on
hmm... i read it from the book. this is the full code, maybe you can take a look:

cell.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
class Cell;
typedef Cell* Link;
class Cell
{
public:
Cell(int iValue, Cell* pNextCell);
int& Value() {return m_iValue;}
const int Value() const {return m_iValue;}
Link& NextLink() {return m_pNextLink;}
const Link NextLink() const {return m_pNextLink;}
private:
int m_iValue;
Link m_pNextLink;
};


cell.cpp
1
2
3
4
5
6
7
#include "Cell.h"
Cell::Cell(int iValue, Link pNextLink)
:m_iValue(iValue),
m_pNextLink(pNextLink)
{
// Empty.
}


main.cpp
1
2
3
4
5
6
7
8
#include <cstdlib>
#include "Cell.h"
void main()
{
Link pCell3 = new Cell(3, NULL);
Link pCell2 = new Cell(2, pCell3);
Link pCell1 = new Cell(1, pCell2);
}


can you tell me what it means? i mean, in cell.h about my question...
Last edited on
Link& is a reference to a pointer. It works the same way as a reference to any other type.
If you pass a reference to an int to a function and the function modifies the int, the caller sees the new value. If you pass a reference to a pointer to an int to a function and the function modfies the pointer, the caller sees the new pointer value.
Topic archived. No new replies allowed.