Q u e s t i o n s . . .

1. Can a class template or a function template have only non-type parameters?
2. Can a template have only specializations without a "general" definition?
3. Is the scope of i and/or j limited to the for loop itself or they are just like any local variable inside Func()? or int j inside a loop is illegal?
1
2
3
4
5
6
7
void func()
{
    for (int i=0;i<6;i++)
    {
        int j=i-9;
    }
}


4. When declaring an array of objects, can I use a non-default constructor? For example:
1
2
3
MyClass obj[5];
MyClass obj(4,true)[5];
MyClass obj[5](4,true);


Is line 2's syntax correct? What about line 3?
Last edited on
1. yes
2. No (You need something to specialize)
3. limited to the loop itself.
4. MyClass obj[5]; //OK
1
2
MyClass obj(4,true)[5]; //WRONG
MyClass obj[5](4,true); //WRONG 


Could you not have tested these out on your own??
Yes, I could, but the weekly time in which I can use a computer with a C++ compiler is very very limited and I'm very busy, so asking saves time. It's faster than doing experiments. I can post a question on a computer without a compiler, to which I have access more frequently...
Can't you just download a compiler?
No, because the computer-without-a-compiler is not mine. It's a public computer. It's located at an internet-library.
and where is the other one?^.-...
It's at home, but I'm not there most of the time...
Sounds like a bad time to start learning c++! You need to put aside a lot of time reguarly.
Indeed, but I'm not learning it anymore. I just ask little questions whenever they arise, but aside from that I write C++ code in my notebooks without needing a tutorial.
Indeed, but I'm not learning it anymore. I just ask little questions whenever they arise


If you're asking questions still... you're learning.
Topic archived. No new replies allowed.