Click here to Skip to main content
15,880,047 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I have class which is several apis which are 2d and 3d .

i have segregated the apis from the cxclass to new classes cxclass1 and cxclass2.


But i have class for existing class ..which should not be changed as part of process (should generally we did typedef cxclass1 cxclass) so calls will shift to new class.

but here i have two classes we cant to do typedef for two classes i want solution regrading this ?

[EDIT: Added from comment below on behalf of OP]
C++
class CDerived1
{
public:

//CDerived1() { cout << "I am Derived1 Constructor" << endl; }
void print() { cout << " I am derived1" << endl; }

void func1()
{
cout << "I am CDerived1 func1" << endl;
}
};



class CDerived2
{
public:

CDerived2() { cout << "I am Derived2 Constructor" << endl; }
void print() { cout << " I am derived2" << endl; }

void func2()
{
cout << "I am CDerived2 func2" << endl;
}
};

class CBase : public CDerived1, public CDerived2
{
public:

CBase() { cout << "I am Base Constructor" << endl; }

void func1(){ ; }
void func2(){ ; }

};


void main()
{
CBase obj;
obj.func1();

//obj.func2();
}
Posted
Updated 14-Jan-16 11:24am
v5
Comments
Sergey Alexandrovich Kryukov 13-Jan-16 1:25am    
It just makes no sense. Can you explain what you really want to achieve?
—SA
[no name] 13-Jan-16 1:35am    
i have once class which is having 2d and 3d APIS .. i segragrated the class ot two classes but now iam not changing the call(i.e normal class) so if i typedef one class complier wil call to new class (i.e 2d) but i have two classes so complier should go to two classes .. but calls will not change please let me know
Sinisa Hajnal 13-Jan-16 2:23am    
That is impossible. Any call in programming must be clear, single meaning, one path only.

Describe what you're trying to do, not like I'm trying to split the class, but what are you trying to achieve. Someone here will suggest how to do it.

If you're just trying to separate 2d and 3d, create two classes that wrap the original and publish only those methods you would like to use.
[no name] 13-Jan-16 5:37am    
want i trying to achieve to is after full completion of testing the class will be removed ..so many callsare there ..so iam not changing the calls..just changing the logics
[no name] 13-Jan-16 1:52am    
Of course you cannot typedef cxclass1 AND cxclass2 as cxclass. What is trhe compiler supposed to do here?

1 solution

It seems that you do not understand what typedef is...
When you write the line
C++
typedef type new_type

you are actually create an alias for type...It is very useful to create shorthand for long type names...
C++
typedef unsigned long ulong

In your case you try to assign the very same alias to more than one types - that's impossible as the compiler will not able to decide what type you actually meant...

If I understand you question, what you actually try to do is to separate functionality of one class into two classes, but do not want to change the existing calls...
What I would advise is to create cxclass1 and cxclass2 and then change cxclass to inherit both...With this your exiting calls will still go to cxclass, but actually execute cxclass1 or cxclass2...New code can access the new classes directly...

An example...
...before
C++
class cxclass {
  public:
    DoSome() {}
    DoOther() {}
}

...after
C++
class cxclass1 {
  public:
    DoSome() {}
}

class cxclass2 {
  public:
    DoOther() {}
}

class cxclass : public cxclass1, public cxclass2 {
}
 
Share this answer
 
v2
Comments
[no name] 13-Jan-16 3:56am    
Thanks for your reply. Can you explain what do you meant by saying "but actually execute cxclass1 or cxclass2." If I derive my cxclass1 and cxclass2 from cxclass. As my object is created for the base class, calls will still go to my base calls. How do i divert them to the derived classes ?
Kornfeld Eliyahu Peter 13-Jan-16 3:57am    
You didn't got it right - see updates...
[no name] 13-Jan-16 4:01am    
which updates ?
Kornfeld Eliyahu Peter 13-Jan-16 4:02am    
These...
[no name] 13-Jan-16 4:50am    
nt wrking its calling only base class apis please let me know

class CDerived1
{
public:

CDerived1() { cout << "I am Derived1 Constructor" << endl; }
void print() { cout << " I am derived1" << endl; }

void func1()
{
cout << "I am base func1" << endl;
}
};



class CDerived2
{
public:

CDerived2() { cout << "I am Derived2 Constructor" << endl; }
void print() { cout << " I am derived2" << endl; }

void func2()
{
cout << "I am CDerived2 func2" << endl;
}
};

class CBase : public CDerived1, public CDerived2
{
public:

CBase() { cout << "I am Base Constructor" << endl; }

void func1(){ ; }
void func2(){ ; }

};


void main()
{
CBase obj;
obj.func1();

//obj.func2();
}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900