|
I want to print out a function pointer using cout, and found it did not work. But it worked after I converting the function pointer to (void *), so does printf with %p, such as
#include <iostream> using namespace std; int foo() {return 0;} int main...
Started by ibread on
, 6 posts
by 6 people.
Answer Snippets (Read the full thread at stackoverflow):
Regarding your edit; ++first) { std::cout << std::hex << std::setw(2) << std::setfill('0') << (int)*first << ' '; } std::cout....
To cout is the right thing (TM) to do in C++ if you want to see their values.
|
|
Hi,
Is it possible to access a base class function which has the same signature as that of a derived class function using a derived class object?. here's a sample of what I'm stating below..
class base1 { public: void test() {cout<<"base1"<<...
Started by Karthik on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
Class.
Test()
You cant override a method in derived class if you dint provide a virtual key word..
|
|
Hi,
I have a question about C++, how to assign a Base object to a Derived object? or how to assign a pointer to a Base object to a pointer to a Derived object?
In the code below, the two lines are wrong. How to correct that?
#include <iostream> ...
Started by skydoor on
, 6 posts
by 6 people.
Answer Snippets (Read the full thread at stackoverflow):
If it's a case of assigning an A that....
Now if you would tell us, what exactly you want to achieve, we might help you .
The other way around (assigning Derived to Base) works, because Base is a subset of Derived.
Prevents you from doing that.
|
Ask your Facebook Friends
|
Class Base { public: void foo() const { std::cout << "foo const" << std::endl; } }; class Derived : public Base { public: void foo() { std::cout << "foo"<< std::endl; } }
I want to make sure that foo() const is correctly hidden...
Answer Snippets (Read the full thread at stackoverflow):
Simply by defining a member function foo in the derived class,....
) { cout << d; } }; class Derived : public Base { void foo(int i) { cout << you don't see the Derived's "foo" hiding the "foo" from the Base.
|
|
Can someone please put me out of my misery with this? I'm trying to figure out why a derived operator== never gets called in a loop. To simplify the example, here's my Base and Derived class:
class Base { // ... snipped bool operator==( const Base& other...
Started by Robin Welch on
, 6 posts
by 6 people.
Answer Snippets (Read the full thread at stackoverflow):
For derived classes to....
It sounds like you want to look could have an overloaded operator== in your derived class that would be able to handle Derived objects.
From base to derived, you are actually creating a new function.
|
|
What's the difference between a derived object and a base object in c++,
especially, when there is a virtual function in the class.
Does the derived object maintain additional tables to hold the pointers
to functions?
Started by MainID on
, 12 posts
by 12 people.
Answer Snippets (Read the full thread at stackoverflow):
derived - is the object....
Virtual() {cout << "Derived::Virtual" << endl;} void NonVirtual() {cout << "DerivedDerived is Base, but Base is not a Derived
base- is the object you are deriving from.
|
|
I know that the derived class can't access the private members of the base class, so why does the derived class inherit the private members of the base class? Is there any case that it is useful?
Thanks!
Started by skydoor on
, 9 posts
by 9 people.
Answer Snippets (Read the full thread at stackoverflow):
The reason is because derived....
An instance of the derived class contains instances by that question.
The derived class doesn't "inherit" the private members of the base class in any way - it can't access them, so it doesn't "inherit" them.
|
|
Given:
#include <iostream> using namespace std; struct Concrete { char name[20]; char quest[20]; char favorite_color[13]; }; struct Concrete_with_knobs : public Concrete { int knobs[1 ]; }; Concrete * cradle() { return new Concrete_with_knobs; }...
Started by Thomas L Holaday on
, 4 posts
by 4 people.
Answer Snippets (Read the full thread at stackoverflow):
Derived : public Base{ int j; };
will any conformant C++ compiler leak memory in the following cases:
// 1 Base* b1 = new Derived(); delete b1; // 2 Base* b2 = new Derived(); void* vp = b2; delete static of the dynamic type (Derived....
|
|
Hello Group,
I am working on a legacy framework. Lets say 'A' is the base-class and 'B' is the derived class. Both the classes do some critical framework initialization. FWIW, it uses ACE library heavily.
I have a situation wherein; an instance of 'B'...
Started by Abhay on
, 6 posts
by 6 people.
Answer Snippets (Read the full thread at stackoverflow):
A solution might be to have a helper object passed from the ....
At the time the constructor of the base class run, the object of the derived class basically doesn't exist.
It really shouldn't be that way.
In the constructor in a derived.
|
|
Hi I'm having problems selecting the correct version of a templated class which has an explicit specialization. I'm wanting to select a specialization using a derived class of the class used to specialize. The scenario is:
#include <stdio.h> class...
Answer Snippets (Read the full thread at stackoverflow):
You can convert a derived object to a base object implicitly::cout << Foo<A>::fooBar() << std::endl; std::cout << Foo<B>::fooBar() << std::endl; std::....
That won't really do you any good though.
|