473,382 Members | 1,392 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

How to initialize a class member shared pointer, to NULL?

Dear C++'ers

I am experimenting with boost shared_pointers.
My Classes

class A
{

private:
typedef boost::shared_ptr<AASharedPtr;
ASharedPtr m_parent; // Keep Track of Parent Node

float m_score; // Total Distance

public:
A(float p_score, ASharedPtr p_ptr ): m_parent(p_ptr)
{
m_score = p_score;
}
};

If i say

ASharedPtr a(new Node(ay, p_ptr));
// where p_ptr already initialzed shared ptr things are quite O.K

but
ASharedPtr a(new Node(ay, 0)); // is not working

Now my question is how to set m_parent to be NULL or 0. I am on VC++
6.0 debugger. It shows m_parent as CXX0030: Error: expression cannot be
evaluated.
I hope I am clear.

Thanking you

Dec 16 '06 #1
1 9211

Pr************@gmail.com wrote:
Now my question is how to set m_parent to be NULL or 0.
You can use deafault constructor e.g:

#include <boost/shared_ptr.hpp>
#include <iostream>

class my_class{
public:
boost::shared_ptr<my_classm_p;

my_class( boost::shared_ptr<my_classp_in): m_p(p_in){}
};
int main()
{
// needs to be done like this else looks like function definition
my_class x = my_class(boost::shared_ptr<my_class>());

if ( ! x.m_p){
std::cout << "OK .. x.m_p is empty\n";
}
else{
std::cout << "something went wrong\n";
}
}

regards
Andy Little

Dec 16 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: MacFly | last post by:
Hi everyone, HRESULT WINAPI DirectPlayMessageHandler( PVOID pvUserContext, DWORD dwMessageId, PVOID pMsgBuffer) I want that method to be class member method so it could have access to class...
1
by: Skavenger | last post by:
Hi, I'm attempting to use a class member function pointer to call a relevant function. This is done like this.... typedef void(SampleA::*SAMPLEAFUNC)(void); class SampleA { public:...
3
by: sathyashrayan | last post by:
The standard confirms that the following initialization of a struct struct node { --- --- } struct node var = {NULL};
30
by: Javaman59 | last post by:
I come from a background of Ada and C++ programming, where it was considered good practice to explicitly initialize every variable. Now that I'm programming in C# I think that it would be best...
0
by: eric | last post by:
Can I declare a pure virtual member function which accepts as input a boost shared pointer to an object of a base class, such that - concrete implementations of the function can redirect the...
7
by: Uwe Grawert | last post by:
Hello, a C-function expects me to give a pointer to a function as parameter. i want to give this function a pointer to a member function of a class but the compiler gives me an error: void...
3
by: tom | last post by:
How to get access to veriable from static class member? class cTest { public: int a; void Set_a(){a = 1;} static int dlgTest()
7
by: WaterWalk | last post by:
Hello. I thought I understood member function pointers, but in fact I don't. Consider the following example: class Base { public: virtual ~Base() {} }; class Derived : public Base {
3
by: Bob Altman | last post by:
Hi all, If I have a class that includes an instance of a struct as a member, how do I initialize that struct? I can't find a syntax for the constructor "initializer list" that works. For...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.