Board.cpp:

#include "Board.h"

Tetris_::Board::Board(int b, int h) {
  width_ = b;
  height_ = h;
}

ostream& operator<<(ostream& out, const Tetris_::Board& brd) {
  out << "(" << brd.width_ << ")";
  return out;
}

Tetris_::Board::~Board() {}

Board.h:

#include <iostream>
#include <stdlib.h>

using std::ostream;

namespace Tetris_ {
  class Board {
    public:
      Board(int b, int h);
      friend ostream& operator<<(ostream& out, const Board& brd);
      ~Board();
      int width_;
    private:
      int height_;
  };
}

main.cpp

#include "Board.h"
#include <stdlib.h>

using Tetris_::Board;
using std::cout;
//using std::endl;

int main(int argc, char* argv[]) {
  Board* brd = new Board(20,20);
  cout << brd;
  return 0;
}

All I get after executing the file is the address of the brd object, and not its width! I think it doesn't "find" the "overloading" and doesn't execute it, but just uses the standart "cout <<" procedure! Where am I wrong?!

You're printing a pointer, of course the result will be an address. Try dereferencing brd:

cout << *brd;
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.