|
if (token = "int") size = sizeof(int);
else if (token = "char") size = sizeof(char);
else if (token = "foo") size = sizeof(foo);
etc..
C/C++ does not have a way to turn input (your parsed source code) into executable code (an actual sizeof(...) operation) on the fly, so anything you do like this has to be done as a lookup table of some kind.
Software | Cleek
|
|
|
|
|
In order to determine the size of a variable in an arbitrary piece of C++ code, you must replicate a significant portion of the functionality in a compiler. This is a major task.
Given that you tried to determine the size of a type based on the sizeof the string containing the type name, I would guess you're fairly new to programming. First of all, the sizeof operator doesn't usually return anything meaningful with regards to the contents of a string, since strings are usually represented as a pointer. Usually you need to use a function or class method that returns the string length. Secondly, the length of the type name has nothing to do with size of the type itself. Here's a couple of examples:
class S {
char data[100000];
};
class ThisIsATypeWithAVeryLongNameAndLotsOfWords {
char data;
}; Both S and ThisIsATypeWithAVeryLongNameAndLotsOfWords are type names, but as you can see, the length of the name doesn't affect the size of the underlying type. S occupies 100000 characters, while ThisIsATypeWithAVeryLongNameAndLotsOfWords only uses one.
What are you trying to accomplish here?
Software Zen: delete this;
|
|
|
|
|
I have very strange problem. See this code:
I used this mfc class to connect to ftp
CFtpConnection *m_pFtpConnection;
CInternetSession m_Session(NULL, 1, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, INTERNET_FLAG_DONT_CACHE);
m_Session.SetOption(INTERNET_OPTION_REQUEST_FLAGS, INTERNET_REQFLAG_CACHE_WRITE_DISABLED);
end the connection:
try {
m_pFtpConnection = m_Session.GetFtpConnection(strHostname, strLogin, strPassword, nPort, bPassive);
m_pFtpConnection->SetCurrentDirectory(strFrom);
here i want get name of the newest file on ftp:
CFtpFileFind finder(m_pFtpConnection);
BOOL bWorking = finder.FindFile((LPCTSTR)strFrom, INTERNET_FLAG_DONT_CACHE | INTERNET_FLAG_RAW_DATA);
FILETIME ft1;
TimeStamp ts1(1971, 1, 1, 0, 0, 0);
TimeStamp ts2;
CString strGetFile;
while(bWorking) {
bWorking = finder.FindNextFile();
finder.GetLastWriteTime(&ft1);
TimeStamp ts2(ft1);
if(!finder.IsDots()) {
if(!finder.IsDirectory()) {
if(ts1
|
|
|
|
|
Hello Friends,
I have a progress bar with some data being displayed in it which is present on the StatusBar. My main problem is when ever I am resizing the window, the progress is not getting resized dynamically. I had used OnSize() member function, then also its not working. Please help me regarding this problem.
thanks in advance.
Neelesh K J Jain.
|
|
|
|
|
Hi!
Can anybody help me about how to hide toolbar and Menubar(File,Edit,View,Favourites,Tools,Help menu items) form Intenet Explorer leaving only the client area. Solution may be a visual c++ program reference or some registry settings.
|
|
|
|
|
Press the f11 hot key when ever u browse the ie
|
|
|
|
|
i am trying to do it in visual c++ so that nobody dare to access it. pressing F11 is a total joke.
|
|
|
|
|
Search for BHO on CP
Thanks
|
|
|
|
|
Search for BHO on CP
Thanks
|
|
|
|
|
hai !
i am facing a pbm in c++ . How can i prevent from inheritance of my class..
example:
class a
{
}
class b:public a
{
}
i want to prevent a from b not inherit like in java final keyword....
|
|
|
|
|
Switch to java
can't do it in C++
-prakash
|
|
|
|
|
can we check in base class constructor with this pointer which class is inveoked with this we can prevent from inheritance
sai
|
|
|
|
|
virtualkirankumar wrote:
can we check in base class constructor with this pointer which class is inveoked with this we can prevent from inheritance
sai
or make all members private. but i dont understand the your intention.
If the user cannot inherite ur class, then the user can certainly write a wrapper over ur class, which you cant prevent.
My suggestion,
be constructive on the class logic. if you are worried about ppl using ur class, just stick a copy right notice on the top.
-prakash
|
|
|
|
|
As Prakash says, there is no keyword for this. But there is a method for getting the same kind of encapsulation.
First you declare the interface for you class in a cpp file, then you declare an implementing class in a header file.
Here's a small example:
The header file dclares the interface Public, and a function that creates an instance:
<span style="color: green;">
<span style="color: blue;">#ifndef</span> _TESTER_H_
<span style="color: blue;">#define</span> _TESTER_H_
<br> <br>
<span style="color: green;">
<span style="color: blue;">class</span> Public
{
<span style="color: blue;">public</span>:
<span style="color: blue;">virtual int</span> GetX() = 0;
};
<br> <br>
<span style="color: green;">
Public * CreatePublic(<span style="color: blue;">int</span> x);
<br> <br>
<span style="color: blue;">#endif</span> // _TESTER_H_
The cpp file declares the implementing class Private:
<span style="color: green;">
<span style="color: blue;">#include</span> "tester.h"
<br> <br>
<span style="color: green;">
<span style="color: blue;">class</span> Private: <span style="color: blue;">public</span> Public
{
<span style="color: blue;">public</span>:
Private(<span style="color: blue;">int</span> x): m_x(x)
{
}
<br> <br>
<span style="color: blue;">int</span> GetX()
{
return m_x;
}
<br> <br>
<span style="color: blue;">private</span>:
<span style="color: blue;">int</span> m_x;
};
<br> <br>
Public * CreatePublic(<span style="color: blue;">int</span> x)
{
return new Private(x);
}
Here's how to use it:
<span style="color: blue;">#include</span> "tester.h"
<br> <br>
<span style="color: blue;">int</span> main()
{
<span style="color: green;">
<span style="color: green;">
<br> <br>
Public * pPub = CreatePublic(42);
<span style="color: blue;">delete</span> pPub;
<br> <br>
<span style="color: blue;">return</span> 0;
}
The funny thing is, that while the Java keyword final optimizes the code by removing the need for a vtable, this C++ technique adds an overlay by creating a vtable.
"After all it's just text at the end of the day. - Colin Davies
"For example, when a VB programmer comes to my house, they may say 'does your pool need cleaning, sir ?' " - Christian Graus
|
|
|
|
|
|
Hi!
I'm using the great COptionTree (http://www.codeproject.com/treectrl/coptiontree.asp)
So far no problems, but then I tried to combine it with a "Sidebanner" (http://www.kinkycode.com/?section=cppdev&sub=kcsidebannerwnd)....in order to have a small image on top of my dialog..
But now i have the problem, that the optiontree "moves under" the bannerimage...
Now here my question..how can i set that the y-position of the optiontree "moves" 40 pixels downwards..?
I think the OnSize function is responsable for my problem..so here the code which i have in my dialog..:
Isn't it possible to just move the OptionTree 40 pixels downwards??
Perhaps somebody can tell me the code, i have to add
void CPrefsDlg::OnSize(UINT nType, int cx, int cy)
{
// Resize the control
if ((cx > 0) && (cy > 0))
{
if (::IsWindow(m_otTree.GetSafeHwnd()))
{
m_otTree.MoveWindow(0, 0, cx, cy);
}
}
CPropertyPage::OnSize(nType, cx, cy);
}code>
mfg
|
|
|
|
|
if you post this question at http://www.codeproject.com/treectrl/coptiontree.asp[^] forum, maybe the author would be in a better position to help you out.
-prakash
|
|
|
|
|
|
aman-ul-haq wrote:
HI!
i am trying to avoid copying files and directories in windows. i want to design a spy application that does not allow me to select edit menu from windows explorer so that i may not select copy & Cut options. Can anybody plz help me in that.
I dont think its a good idea, how would you block a person issuing copy commands from the dos shell.
if at all you still want to do it, you need to write a filesystem device driver for that.
-prakash
|
|
|
|
|
Strictly saying, it's not a spy program, rather an admin tool.
But I can't think of any way to do it but messing with the explorer window ("disabling" menu items and toolbar buttons etc). However, any 3rd party software will still be able to copy anything...
|
|
|
|
|
I tried the function InternetDial, so how to point automatically in the internet call dialog my default connection?? And another question, how to handle the connected and disconnected status of my connection? I've red about call back function, but can't understand how to use it, are any examples in the internet?
|
|
|
|
|
Does anyone of you know how to develop a tool like tcpview(by sysinternals.com)? My requirement is to not just listing (as in TCPview) but to monitor and end a process before it actually starts. For example, i want to filter all applications passing through port 80 except Internet Explorer. so if some clicks any pdf file on Internet, he will not be allowed to do so? how do i proceed? i m really clueless and need some ideas.
Thanking u,
|
|
|
|
|
how can i get network ip address or
com port address(device)or
another computer which have entire network.
|
|
|
|
|
vc-programmer- wrote:
how can i get network ip address...
To get the IP address of a machine, use gethostbyname() .
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
in win32 console application you need to include windows.h and provide kernel32.lib to the linker.
-prakash
|
|
|
|