Click here to Skip to main content
14,585,336 members
Rate this:
Please Sign up or sign in to vote.
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]
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
   
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?
[no name] 13-Jan-16 5:03am
   
any other solution
[no name] 13-Jan-16 5:14am
   
To what? You have not yet asked a clear and thought out question. This is a technical forum. Solutions are given to match questions. We can't guess at what you want. Use improve question and explain exactly your problem.
[no name] 13-Jan-16 5:25am
   
i segragrated the class into two classes but now iam not changing the call(i.e normal class) so if i typedef one class complier call will go 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
[no name] 13-Jan-16 5:29am
   
i have one class which is having two apis(i.e 2d and 3d) i merged in two classes as a part of refactoring but ..i did typedef of existing class ( how to typedef two classes) its not possible ..so want any other method ( as i should not change the existing class)
Ralf Meier 13-Jan-16 6:39am
   
I would suggest the Following :
Make an exact Example (perhaps with some code) to explain what you try to achieve. Don't describe it with words - as you can see - your description until now isn't understood - and this not only from one guy ...
As another user (OG ?) sometimes write : We don't sit in front your PC, we don't see what happens and sometimes our glassorb doesn't Show the right things ...

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

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

you are actually create an alias for type...It is very useful to create shorthand for long type names...
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
class cxclass {
  public:
    DoSome() {}
    DoOther() {}
}

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

class cxclass2 {
  public:
    DoOther() {}
}

class cxclass : public cxclass1, public cxclass2 {
}
   
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();
}
nv3 14-Jan-16 17:23pm
   
You should use the grren "Improve solution" button to amend your question. I have done that for you now.

To your problem: You are mixing up what a base class and a derived class is! In your example, CDerive1 and CDerived2 are in fact the base classes and CBase is derived from them. By using the wrong terminology you are not likely to get an answer to your actual problem, which I have not understood by now. Try to rephrase your question using the correct terminology.

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100