Thread: templates

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Dec 2007
    Posts
    15
    Hey matsp. I tried both you're solutions but that doesn't seem to be the problem...

    any other ideas?

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Not at this time. I'm sure someone else will come along and give you a better answer - it's well past my bedtime, really.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    First of all it's "int main()", not "void main()" void has never been a valid return type for main in C or C++.

    Next, you need to deal with the compiler errors in the order they appear in the build output. Prior to the error you mentioned you should get the following error:
    Code:
    error C2955: 'Sqr' : use of class template requires template argument list
    That is telling you that you need to use Sqr<int>::doIt. The compiler isn't goint to try and work out the parameter types for the member function when it doesn't even know what class instantiation you're talking about first.
    Then after fixing that you'll get the following error:
    Code:
    error C2352: 'Sqr<T>::doIt' : illegal call of non-static member function
    This means you either need an object of type Sqr<int> to call this on, or you need to declare the function as static. I assume the later is intended here.
    Now magically the other error has vanished. If you don't start with the first error you can quite often be looking at an error that is simply a consequence of an earlier error, and not actually an error in itself at all.

    This also then wont compile:
    Code:
    		for (T* i=begin, int z = 0; i != end; i++, z++)
    You can't declare two variables of different types in a for-loop. And this look like you're attempting to call an int as though it is a function!
    Code:
    			begin[z](3);
    I suggest perhaps getting the code you're writing to work with concrete types first, and then convert it to template code.
    Last edited by iMalc; 02-04-2008 at 12:11 AM.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by iMalc View Post
    That is telling you that you need to use Sqr<int>::doIt.
    Well actually, as you know, the compiler can figure that out. The problem lies in that the class function is not static or the OP isn't calling the function on an actual instance of the object.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Templates from DLL or static library problem
    By mikahell in forum C++ Programming
    Replies: 2
    Last Post: 01-01-2008, 01:49 AM
  2. Questions about Templates
    By Shamino in forum C++ Programming
    Replies: 4
    Last Post: 12-18-2005, 12:22 AM
  3. templates and inheritance problem
    By kuhnmi in forum C++ Programming
    Replies: 4
    Last Post: 06-14-2004, 02:46 AM
  4. When and when not to use templates
    By *ClownPimp* in forum C++ Programming
    Replies: 7
    Last Post: 07-20-2003, 09:36 AM