pointer to an object has no any value (or do not get a value)

i have a problem with output of 2 classes like below:

Foo.cpp

Foo::Foo(string n):foo(n){ }  Foo::Foo(const Foo &f):foo(f.foo){ }  string Foo::getFooName() const{     return foo; }  Foo::~Foo(){ } 

and class Bar:

Bar.h

public:     Bar();     Bar(string, Foo&);     Bar(const Bar&);     Foo& getFoo() const;     ~Bar(); private:     string bar;     Foo* foo; }; 

Bar.cpp

Bar::Bar(string b, Foo &f):bar(b), foo(new Foo()){ }  Bar::Bar(const Bar &b):bar(b.bar), foo(new Foo(*b.foo)){ }  Foo &Bar::getFoo() const{  return *foo; }  Bar::~Bar() { delete foo; } 

and in main fuction, when i use this cout<<"Test:"<<b->getFoo().getFooName(); it only gets me in output only Test: instead of Test:TestFoo.

what is wrong in my code? (gcc5.4.0,cmake 3.5.1) tnx

and main.cpp

Foo* f; Bar* b; f=new Foo("TestFoo"); b=new Bar("TestBar",*f);   cout<<"Test:"<<b->getFoo().getFooName(); // this line 

Replay

Category: c# Time: 2016-07-29 Views: 0
Tags: pointers class

Related post

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development

search

Front-end development

Database

development tools

Open Platform

Javascript development

.NET development

cloud computing

server

Copyright (C) avrocks.com, All Rights Reserved.

processed in 0.118 (s). 12 q(s)