|
To be frank, I don't know how to interpret it and what it is supposed to be or to do.
You got a class containing an array of its own member variable addresses ?
ilostmyid2 wrote: if u mean the offset of them from the beginning of the class instance, we should use offsetof() in such a case which is completely different from this.
I don't mean anything ...
Debugging that code will display something like:
-A::m_values 0x00e77000 struct A::Info * A::m_values {a=0x00000000 } A::Info [2]
- [0] {a=0x00000000 } A::Info
+ a 0x00000000 int *
- [1] {a=0x00000004 } A::Info
+ a 0x00000004 int *
Where m_values[0] is the offset of the first variable and m_values[1] is the offset of the second variable...
It is quite an ugly piece of code.
Please explain what it is supposed to do .
Watched code never compiles.
|
|
|
|
|
I agree with you, don't see the point in having that array for a number of reasons... its static, so it'll only contain two values regardless of the number of instances of A, and those variables are public anyway, so what's the point of accessing them via a static array?
|
|
|
|
|
indeed it's not a code of mine or my friend. this a piece of a large project which my friend uses. they have to port the whole project containing the code from vc6 to vs2010. so, i'm not the writer and i don't know what has been the aim. eg. int is my replacement to CButton for simplification. the structure is not changed though.
|
|
|
|
|
Well, now the code compiles.
Just run it and see if the behaviour changes from VC6 to VS2010 ...
If it does not work as intended, then either try to understand what it is supposed to do or re-write it.
Watched code never compiles.
|
|
|
|
|
the code compiles only in vc6. in vs2010 i get an error indicating that the array cannot be initialized with &a and &b because they must belong to an instance of A and this is reasonable.
i need to know whether it's a bug of vc6 compiler or the vc6 compiler interprets it and makes in sense in a way that vs2010 doesn't.
|
|
|
|
|
My first answer fixed the compilation error.
In my opinion, this code is crap and should be rewritten/replaced with good meaningful code.
Check to see in real life ( in your actual code) if that still works (run) and it is doing what it is supposed to do.
Since I really don't know what this code is supposed to do (do you even know what it is supposed to to ?); I cannot help you more.
Good luck with that.
Max.
Watched code never compiles.
|
|
|
|
|
as i mentioned b4, i myself don't know what the code is supposed to do too. i just see that vc6 can realize it and guess the writer has written the code in the way it understand. i just need to know what does the code do so that i may port it to vs2010 to do the same behavior. that's all.
|
|
|
|
|
ilostmyid2 wrote: i myself don't know what the code is supposed to do too
ilostmyid2 wrote: i just need to know what does the code do
Interesting...
So you already know what you have to do; you said it yourself: understand the code.
Or, make said modification that allows the code to compile, and it'll probably work exactly like it did in VC6.
|
|
|
|
|
i created this topic for this, to get help to understand what does the code do!
|
|
|
|
|
From the discussions, it looks like the code is attempting to select 'the same' button (int in the modified example) from every instance of class A, using an index and the Info array.
So, as a way of selecting the first or the second button on each instance of A and working with that.
int whichButton = 1; A* arrayOfA = ...
for (int i = 0; i < numOfAs; i++)
{
CButton& button = arrayOfA[i].*(A::m_values[whichButton]);
... }
Or something like that. It's probably a good idea to find out what the code does with this. You should search for all references to A::m_values and find out what exactly it's for.
Then, think of a proper way of implementing that, or verify that it still works and keep it.
|
|
|
|
|
let's continue with a completed code. i wonder that it really works and it's not going to be a mistake or bug of the compiler:
#include "StdAfx.h"
using namespace std;
class A
{
public:
struct Info
{
int A::*a;
};
int a, b;
static Info m_values[];
void f();
};
A::Info A::m_values[] = {&a, &b};
void A::f()
{
int a = this->*(m_values[0].a);
int b = this->*(m_values[1].a);
cout << "m_values: " << a << ", " << b << endl;
}
void f()
{
A a1, a2;
a1.a = 10;
a1.b = 11;
a2.a = 20;
a2.b = 21;
a1.f();
a2.f();
}
the output is:
m_values: 10, 11
m_values: 20, 21
so how does vc6 implements this and what's the equivalent code in vs2010?
thx
|
|
|
|
|
ok, i found it at last. it's enough to replace &a and &b in the initialization of m_values with &A::a and &A::b. thank u Maximilien. i couldn't figure it out sooner.
|
|
|
|
|
Hello,
I'm Using a 3rd party software that uses log4cxx as its logging provider.
I'm intersted in directing the log to a log4net appender, since my other programs uses log4net.
Can anyone help me ?
thanks,
berlus
|
|
|
|
|
Ask the person who provides the 3rd party software.
|
|
|
|
|
Choices would be
1. Write a lot of code to create a C appender that wrap .Net functionality.
2. Write, or get, a C appender that uses something like TCP. Then set up a .Net server to receive it.
Berlus wrote: since my other programs uses log4net.
Hopefully there is more to it than that.
|
|
|
|
|
In the "INDEX" tab of the explorer,If I look for a function(such like GetDlgItemInt), the explorer always list mobile function( GetDlgItemInt) entry first, I have to switch to platform sdk entry over and over again. It's kind of annoying.
How Can I make the Platform SDK entry topmost or simply eliminate those entries getting in the way?
|
|
|
|
|
1. This has nothing to do with C++.
2. Change the "Refine Search" options in the left hand pane.
|
|
|
|
|
Sorry. There isn't any column fit this kind of problems, but it is a problem related to using VC.
|
|
|
|
|
This is nothing to do with C++/MFC, it is purely to do with your Help settings/options in Visual Studio, which you will need to change.
|
|
|
|
|
These day I install Win7 and I use only in VC6. But I have a weird problem : when I try to use 'Open File' ( Ctrl+O ) , VC6 crush down ... I could open a workspace, but not a file ... why ?
|
|
|
|
|
Flaviu2 wrote: I use only in VC6
Have you applied latest service pack i believe SP6 on VS6.., also try to run in compatibility mode of window XP
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
Also, try running it elevated
|
|
|
|
|
I don't know how ... I use Win7 for few days ...
|
|
|
|
|
First of all, is there a reason that you are using VC6? The environment was built for Win98 and was already slightly dated at the time of WinXP (didn't always function 100%). It might be wise to make the switch to Visual C++ 2010 (Express Edition for home use).
At any rate, if you're stuck with VC6 for a reason, installing the service packs can help increase stability, compatibility and security, so it's a good advice to install them.
To run the studio in elevated mode is a bit bothersome, but can be done by right-clicking the executable or shortcut to the executable and selecting "Run as Administrator".
There is no easy way to run it elevated when you double click a project file from explorer, unfortunately.
I know Visual Studio 2007 even came with the advice to run elevated on Vista/Win7 (along with the advice to upgrade to 2010 to avoid this and other issues), so that's why it's probably useful for VC6 too.
Another thing, try to avoid navigating to Libraries inside VC6 file browse dialogs. I've seen several pre-Win7 applications crash when trying to navigate to a Library (such as the Documents library which includes both the My Documents folder and the Public Documents folder).
Finally, you can try playing around with the Compatibility settings, such as setting its environment to WinXP (or Win98) and seeing if that helps any.
Hope any of this helps. Best advice in this text is: go to a newer version of Visual Studio if you can.
|
|
|
|
|
No, I haven't install any SP ... should I ?
|
|
|
|