|
Can you show code, you are expecting to generate this warning ? Which IDE you are using ?
|
|
|
|
|
The code is something like
<br />
class Value<br />
{<br />
public:<br />
Value(double v);<br />
double getValue() const;
private:<br />
double val;<br />
};<br />
<br />
int main()<br />
{<br />
Value v1(11.0);<br />
int a = v1.getValue();
}<br />
gcc generates warning for this but the vc++ compiler is not generating any warning. I am Visual Studio .net 2002.
Thanks a lot
|
|
|
|
|
This clearly generates warning with level 4 on VC6 and with level 3 on VS2K5 .
Mithin wrote: I am Visual Studio .net 2002
I dont have this IDE to test. But that should not be problem. I thing you are not setting warning level properly.
Test this code with VC6 .
|
|
|
|
|
prasad_som wrote: You need to use warning level 4.
...
But it is not recommended to this level. As, warnings though this level can be safely ignored.
Not? I always set my projects to warning level 4 and try my best to eliminate all warnings.
You may be right I may be crazy -- Billy Joel --
Within you lies the power for good, use it!!!
|
|
|
|
|
PJ Arends wrote: Not? I always set my projects to warning level 4 and try my best to eliminate all warnings.
Same here. To suggest otherwise is bad advise.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
The version of STL that came with VC6 would overwhelm you with warnings, but later versions have fixed that. Even with VC6 a couple of pragmas in the stdafx.h header file would eliminate those errors. There is an article somewhere here on CP on how to do that.
You may be right I may be crazy -- Billy Joel --
Within you lies the power for good, use it!!!
|
|
|
|
|
PJ Arends wrote: The version of STL that came with VC6 would overwhelm you with warnings, but later versions have fixed that.
True.
As mentioned earlier, this particular warning is level 3 though in VS2K5 .
|
|
|
|
|
prasad_som wrote: But it is not recommended to this level. As, warnings though this level can be safely ignored.
I don't think that an implicit conversion from double to int should be ever safely ignored.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
Yes. I was refering to level 4 warnings. As you can see my further posts about this particular warning. Should be treated as level 3 warning and it is level 3 warning in VS2k5 .
|
|
|
|
|
I used a COleDateTime variant and also has initialized it, but when I want to store it in a CString object, using the Format(...) function,there would be some wrong: it refuse to work!.
somebody would tell me why,and how to resolve it?
Thanks Very Much!
|
|
|
|
|
It seems to work for me. Try this:
COleDateTime dt(1971, 6, 12, 12, 0, 0);
CString s = dt.Format();
AfxMessageBox(s);
Steve
|
|
|
|
|
Can you show code, what you are trying ?
|
|
|
|
|
COleDateTime time(1996,1,1,0,0,0);
int status=time.GetStatus();
cout<
|
|
|
|
|
kcynic wrote: str=time.Format("%Y %m %d %H:%M:%S");//Wrong
Whats wrong here ? I can see its formating time , as it should.
i.e. "1996 01 01 00:00:00"
|
|
|
|
|
I have created a class file and class header- in the header I save version,file name, and # of last file saved
then everything after that is the file storage.. The problem I am having is: my index has a bug-
reading the file:
file k[150];
header hdrs;
ifstream op("file.dat",ios::nocreate);
op.read(reinterpret_cast <char*> (&hdrs),sizeof(header));
op.read(reinterpret_cast <char*> (&k),hdrs.index * sizeof(file));
saving the file:
strcpy(k[hdrs.index].first_name,s);
m_last.GetWindowText(f);
strcpy(k[hdrs.index].last_name,f);
ofstream fi("file.dat",ios::nocreate);
if(!fi.is_open())
{
MessageBox("File failed!","",MB_OK);
}
hdrs.index++;
s.Format("File Storage system");
strcpy(hdrs.title,s);
s.Format("1.0");
strcpy(hdrs.version,s);
fi.seekp(0,ios::cur);
fi.write(reinterpret_cast <char*> (&hdrs),sizeof(header));
fi.write(reinterpret_cast <char*> (&k),hdrs.index * sizeof(file));
fi.close();
after saving a number of data items the index looses count and gives me a number:-858993460
It works sometimes for a while before loosing count and other times right off the start..
any ideas why?
-- modified at 20:15 Monday 8th January, 2007
|
|
|
|
|
I can't see and "<"s or ">"s in your code. This makes it hard to see what you're casting to.
Steve
|
|
|
|
|
"<"char * ">"
sorry, did not notice it would not show up!
|
|
|
|
|
"<"char * ">"
They are all the same... I am just learning on how to do this..
This file.dat is pre-created
at the start of the program-with just the header and index set to 0..
I use a dialog box and CEdit box to get entries.
-- modified at 20:50 Monday 8th January, 2007
|
|
|
|
|
Try using the ios::binary flag. i.e.
ifstream op("file.dat", ios::binary);
Steve
|
|
|
|
|
I have - I am not sure why its doing this!
last night I saved 150 data items and read them fine.. once it hit 151 it crashed . I deleted that file and started again and I entered 6 items and it crashed?
I am lost on what is causing this- I can't tell if its before the save or during. I have tried debuging it I can only think its happening during the saving process?
since it works some of the time..
by the question I trying yo solve is why..
hdr.index++;//could this be the problem?
|
|
|
|
|
I'm not sure. I'd need to see more code.
Steve
|
|
|
|
|
|
I'm not sure, why you have not used c'tor to initialize member variables.
Dosin wrote: class header
{
public:
char version[6];
char title[20];
int index;
header();
virtual ~header();
};
Not sure , whats happening there. But, change datatype of index to long . And initialize all variables in c'tor.
|
|
|
|
|
Well I think I figured it out-it was the nocreate.. for some reason it stopped the file from writing at random.. I changed it to ios::binary - it seems to be working - more testing it needed.. the size int is fine for my program.. I am making a program to hold up to 15000+.. files.. (why you have not used c'tor ) I just needed a data class and used the class instead of a struct.. It works kind of like a bitmap file.. If you read or create a bit map you can use a strut or a class.. if for some reason it fails again I will try that! thanks for all the help!!!
so far 103 entries and no errors! Ya!
|
|
|
|
|
You classes have virtual functions. For one thing, you shouldn't "twiddle bits" is classes that have (virtual functions) in the manner you are. In classes with virtual functions the compiler inserts code in the constructor and destructor to initialise the vtable pointer: your code will stomp of the compilers good work if the vtable is located at a different address (either because of a rebuild or code in a DLL being relocated). This is a classic example of what can happen when low level constructs such as "bit twiddling" are mixed with high level ones such as virtual functions.
Steve
|
|
|
|