compiling discrepencies

This is a discussion on compiling discrepencies within the C++ Programming forums, part of the General Programming Boards category; this is driving me crazy in devc++ i'm NOT creating a project. I'm compiling w/ -ansi -pedantic -Wall -Wextra -Werror ...

  1. #1
    Registered Abuser
    Join Date
    Sep 2007
    Location
    USA/NJ/TRENTON
    Posts
    127

    compiling discrepencies

    this is driving me crazy

    in devc++ i'm NOT creating a project. I'm compiling w/ -ansi -pedantic -Wall -Wextra -Werror
    if i have a class in a header file like so:
    Code:
    template <typename T> class myClass
    {
        public:
            myClass();
            ...
    };
    and define the constructor in a source file like so:
    Code:
    template <typname T> myClass<T>::myClass<T>()
    {
        ...
    };
    it works just fine.


    But when I compile the same stuff in cygwin w/the same options, it tells me I have undefined references to my constructors.

    WTF???

  2. #2
    Registered Abuser
    Join Date
    Sep 2007
    Location
    USA/NJ/TRENTON
    Posts
    127
    BTW, here's my makefile for gcc:
    Code:
    COMPILECPP=g++
    FLAGS=-g -DDEBUG -ansi -Wall -Wextra -pedantic -Werror
    CPPSRC=$*.cpp
    BUILDCPP=$(COMPILECPP) $(FLAGS)
    BUILDMAINCPP=$(BUILDCPP) -o
    .SUFFIXES:
    .SUFFIXES: .c .cpp .h .o
    .cpp.o: ; $(BUILDCPP) -c $(CPPSRC)
    
    all: List
    
    clean:
    	rm -rf *.o a.out
    	
    List: Driver.o List.o SysCalls.o
    	$(BUILDMAINCPP) List Driver.o List.o SysCalls.o
    
    SysCalls.o: SysCalls.cpp SysCalls.h
       
    List.o: List.cpp List.h
    
    Driver.o: Driver.cpp List.h SysCalls.h

  3. #3
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    23,803
    When writing template classes, do not separate the class declaration from its implementation. Read: Why can't I separate the definition of my templates class from it's declaration and put it inside a .cpp file?.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  4. #4
    Registered Abuser
    Join Date
    Sep 2007
    Location
    USA/NJ/TRENTON
    Posts
    127
    oh oh oh OK. yea i've heard that before. because *templates* aren't treated the same as
    a *non-templated* class. you're the coolest!

  5. #5
    Registered Abuser
    Join Date
    Sep 2007
    Location
    USA/NJ/TRENTON
    Posts
    127
    so the whole:
    Code:
    template <typename T> myClass<int>::myClass<int>();
    acts as a prototype of sorts?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling Issues
    By pc_doctor in forum C Programming
    Replies: 3
    Last Post: 11-30-2007, 09:00 AM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  3. Problem Compiling
    By Flakster in forum C++ Programming
    Replies: 4
    Last Post: 06-13-2006, 01:09 AM
  4. Compiling
    By Dae in forum C++ Programming
    Replies: 7
    Last Post: 06-15-2005, 01:08 AM
  5. Compiling in Unix vs Visual C++
    By stimpyzu in forum C++ Programming
    Replies: 2
    Last Post: 09-30-2002, 06:41 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21