•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 391,686 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,209 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser:
Views: 123 | Replies: 1
![]() |
•
•
Join Date: Jul 2008
Posts: 1
Reputation:
Rep Power: 0
Solved Threads: 0
Board.cpp:
Board.h:
main.cpp
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?!
#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:
cplusplus Syntax (Toggle Plain Text)
cout << *brd;
Member of: Beautiful Code Club.
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
•
•
•
•
age amd avatar blue gene business chips database development dos economy energy enterprise environment epson hardware ibm ibm. news intel ibm it linux medicine memory microsoft news office open source openoffice pc printing ps3 recession recycle red hat remote working russia security sex sun supercomputer supercomputing technology trends ubuntu working x86
- Previous Thread: What do you think? BS tree or AVL tree for fast searching?
- Next Thread: Is this correct?



Linear Mode