|
# define SEMI ;
Or, on the command line:
F:\Projects>type nosem.c
void main(void) { printf ( "Hello, world!" ) SEMI }
F:\Projects>cl.exe /nologo /FIstdio.h /DSEMI=; nosem.c
nosem.c
F:\Projects>nosem
Hello, world!
F:\Projects>
modified 29-Oct-14 11:51am.
|
|
|
|
|
For MS VisualStudio, this should work:
int main()
{
#pragma message ("Hello World!")
}
It will generate the message "Hello World at compile time, even if the ';' key is broken on your keyboard. see http://msdn.microsoft.com/en-us/library/x7dkzch2%28v=vs.100%29.aspx[^]
On a sidenote, you can write C++ programs without the use of many central characters by using digraphs and trigraphs[^]. However, ';' is ot one of the characters you can circumscribe that way, and you can't express any command that will be executed at runtime without it.
GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)
|
|
|
|
|
"Network Access: Allow anonymous SID/Name translation" ,a am attempting to get this via the registry but cant find the key,how can I get thisvalue ,tks
"Network Access: Allow anonymous SID/Name translation" ,a am attempting to get this via the registry but cant find the key,how can I get thisvalue ,tks
|
|
|
|
|
|
Dear Friends,
I want to constructor a storage class, which should have the ability to store Tree data in tree hierarchy manner. For example:
Like Root folder -->sub folders---> sub folders --> files.
your suggestion and guidance are highly appreciate.
Thanks and Regards,
S Shanmuga Raja
|
|
|
|
|
You could just use a Treeview control, which has all the functionality built in.
|
|
|
|
|
Actually in want to store it in vector or list or any other data structure. For that, I want to constructor class.
|
|
|
|
|
Then you need to think about the actual requirements of your class and create a design that will match those requirements. With such a vague question it is impossible to suggest much more.
|
|
|
|
|
That's a lot of overhead, presumes a Windows platform, and pulls in a lot of GUI-related dependencies just to store some data.
|
|
|
|
|
Not so, it's a quite simple way of creating the structure that the OP asked about. There is no GUI overhead if the control is never displayed.
|
|
|
|
|
There is code size overhead for pulling in a GUI library which may not be needed. For instance, a in a command-line application, linking in Treeview (and all classes it depends on) could significantly affect the size of the executable, the time to start up, and it would also affect portability of the code.
|
|
|
|
|
All I did in my initial response was to suggest a possible solution to what was a fairly vague question. I leave it to the OP to decide whether that helps to solve their problem.
|
|
|
|
|
Assuming you have string leafs (e.g. file names) in your branches, the minimal structure is:
struct StringTreeNode
{
std::string name;
std::vector<StringTreeNode> branches;
}
A leaf is just a branch with no subnodes.
|
|
|
|
|
Check out http://tree.phi-sci.com/index.html[^]. The documentation offers some insight into its proper use with the two types of iterators it provides.
GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)
|
|
|
|
|
You can use a struct or a class with nested vector of same type structs:
#include <vector>
#include <string>
#include <iostream>
struct TreeNode {
std::string payload;
std::vector<TreeNode> children;
TreeNode(const std::string &p): payload(p) {}
TreeNode() {} };
void walk_tree(TreeNode &node, int indent = 0) {
std::cout << std::string(indent * 4, ' ')
<< node.payload << std::endl;
for (size_t i = 0; i < node.children.size(); ++i)
walk_tree(node.children[i], indent + 1);
}
int main() {
TreeNode a("home");
a.children.push_back(TreeNode("peter"));
a.children.push_back(TreeNode("jane"));
a.children[0].children.push_back(TreeNode("game.exe"));
a.children[1].children.push_back(TreeNode("homework.txt"));
walk_tree(a);
return 0;
}
|
|
|
|
|
I hope I can explain this.
I need to have an array of classes ( CTrackSwitch) as a variable in a class (COpenTrack).
class COpenTrack
{
public:
CTrackSwitch trackSwitch[10];
COpenTrack(void);
….
I can initialize each array class using constructors, each with different parameters.
But initialization only works when done in a method of the “mother” class.
I did try to do it in the COpenTrack constructor, it compiles but there are no data in an array classes. I am missing something.
boolean COpenTrack ::SwitchRoute( int iTrack)
{
// TODO works as local variable only - not as COpenTrack variable
CTrackSwitch trackSwitch[] = {
CTrackSwitch(0,2,8,4),// normal reverse, input , switch start with even tracks from 0
CTrackSwitch(4,6,10,6),// normal reverse, input , switch
CTrackSwitch(1,3,9,3),// normal reverse, input , switch
CTrackSwitch(5,7,11,5),// normal reverse, input , switch
CTrackSwitch(8,10,12,2),// normal reverse, input , switch
CTrackSwitch(9,11,13,1),// normal reverse, input , switch
CTrackSwitch(12,13,14,0)// normal reverse, input , switch
};
…..
Any help would be appreciated.
Cheers Vaclav
|
|
|
|
|
if you can make trackSwitch static, you can do this:
class COpenTrack
{
public:
static CTrackSwitch _trackSwitch[10];
COpenTrack(void)
{
}
};
CTrackSwitch COpenTrack::_trackSwitch[] =
{
CTrackSwitch(0,2,8,4), CTrackSwitch(4,6,10,6), CTrackSwitch(1,3,9,3), CTrackSwitch(5,7,11,5), CTrackSwitch(8,10,12,2), CTrackSwitch(9,11,13,1), CTrackSwitch(12,13,14,0) };
|
|
|
|
|
Boy that was fast. Thanks.
I will try your way first.
I think I'll punish myself and see if I can initialize it using constructor same way as I did the array.
Cheers Vaclav
|
|
|
|
|
What about something like:
COpenTrack::COpenTrack()
{
trackSwitch[0] = CTrackSwitch(0,2,8,4),
trackSwitch[1] = CTrackSwitch(4,6,10,6),
...
}
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
David,
it works, but it is "not cool", just "plain" variable initialization.
I did try to initialize the whole array in default constructor and it did not fly.
I would probably get more descriptive error messages from some other IDE to figure it out.
It should be same syntax I used for the CTrackSwitch, but I thing the array is messing it up.
....
int iNormal; // passing thru
int iReverse; // turning
int iInputTrack; //
int iSwitch; // may be usefull elesewhere
// initialize using constructor
CTrackSwitch(int iNormalInit,int iReverseInit,int iInputTrackInit, int iSwitchInit )
{
iNormal = iNormalInit;
iReverse = iReverseInit;
iInputTrack = iInputTrackInit;
iSwitch = iSwitchInit;
}
....
This is one attempt which actually compiled
COpenTrack(class CTrackSwitch() )
{
trackSwitch[10] = CTrackSwitch();
}
but I could not get the constructor to work.
Oh well, thanks for your help.
Cheers Vaclav
|
|
|
|
|
In C++11 you should be able to use an initializer list just as you did in your local variable example. See http://stackoverflow.com/questions/161790/initialize-a-const-array-in-a-class-initializer-in-c[^]
That said, of course your compiler needs to support it before you can use that syntax.
GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)
|
|
|
|
|
I have a function which recursively scans an array for a matching value and when found processes it and returns. Since it works recursively a single return obviously won't do.
I was hoping I could have a static counter of the recursive calls but have no idea how to implement multiple returns.
I am doing this on Arduino, so KISS is important to me.
Any help would be appreciated.
Thanks Vaclav
|
|
|
|
|
Just make the function return true if a matching value is found and false otherwise. Then, when a return of true is received, simply exit the function without further processing and this will unwind the stack.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
It is not really obvious if recursion needs multiple return statements.
It all really depends on the logic being implemented.
So if you've implemented it and are not getting the expected results, posting the relevant code should get the good people here to help you figure out the problem.
«_Superman_»
I love work. It gives me something to do between weekends.
Microsoft MVP (Visual C++) (October 2009 - September 2013) Polymorphism in C
|
|
|
|
|
You may be right that I am not sure about the "returns".
But debugging in IDE which lacks debugger you kinda flying blindfolded.
I'll try different way to skin this cat!
|
|
|
|
|