views:

27

answers:

2

The title can be confusing, but I'm wondering is it possible to create program like this one:

class family_tree
{
private:
    string name, surname;
    family_tree father(); //fragile point!

public:
    family_tree();
    family_tree(string n, string sur");
    void print();
};

What standard is saying about such declaration? What the good habits of programming saying about it? Is it dangerous?

What is more I can't use the second constructor:

family_tree father("A","B");

compilator:

expected identifier before string constant

expected ',' or '...' before string constant

I will be thankful for any help

+1  A: 
class family_tree
{
private:
    string name, surname;
    family_tree father(); //fragile point!

public:
    family_tree();
    family_tree(string n, string sur); // note that I removed a " here.
    void print();
};

It's perfectly valid. Your fragile point is not fragile at all- you have a function that returns a family_tree, and it doesn't matter that it's called on a family_tree object. Whether or not the language provides for you to implicitly cast the const char* string literal to the std::string, I can't recall.

DeadMG
A: 

upss..you're right DeadMG I just declared function. Somebody before you(he deleted message?) wrote that I can declare pointer to object family_tree *father; I think it's the best solution for my problem

lvp